#include <bits/stdc++.h> #define int long long #define mp make_pair #define pb push_back #define ld long double #define pii pair<int,int> #define sz(x) (int)x.size() #define piii pair<pii,pii> #define precise cout<<fixed<<setprecision(10) #define st first #define nd second #define ins insert #define vi vector<int> #define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std; int32_t main(){ BOOST; int n; cin>>n; string s; cin>>s; int ones=0; for (auto it:s){ ones+=(it=='1'); } if (ones<3 || n*6<ones || n*3>ones){ cout<<"NIE"; return 0; } string ans=""; for (int i=1;i<=n;i++){ if (i==n){ assert(ones>=3 && ones<=6); if (ones==3)ans+='a'; else if (ones==4)ans+='c'; else if (ones==5)ans+='k'; else ans+='w'; } else{ if (ones-3-(n-i)*6<=0)ans+='a',ones-=3; else ans+='w',ones-=6; } } assert(sz(ans)==n); cout<<ans; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #include <bits/stdc++.h> #define int long long #define mp make_pair #define pb push_back #define ld long double #define pii pair<int,int> #define sz(x) (int)x.size() #define piii pair<pii,pii> #define precise cout<<fixed<<setprecision(10) #define st first #define nd second #define ins insert #define vi vector<int> #define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std; int32_t main(){ BOOST; int n; cin>>n; string s; cin>>s; int ones=0; for (auto it:s){ ones+=(it=='1'); } if (ones<3 || n*6<ones || n*3>ones){ cout<<"NIE"; return 0; } string ans=""; for (int i=1;i<=n;i++){ if (i==n){ assert(ones>=3 && ones<=6); if (ones==3)ans+='a'; else if (ones==4)ans+='c'; else if (ones==5)ans+='k'; else ans+='w'; } else{ if (ones-3-(n-i)*6<=0)ans+='a',ones-=3; else ans+='w',ones-=6; } } assert(sz(ans)==n); cout<<ans; return 0; } |