#include<bits/stdc++.h> using namespace std; typedef long long ll; #define SIZE(x) (int)x.size() #define REP(x,t) for(ll x=0; x<(t); x++) #define FOR(x,t) for(ll x=1; x<=(t); x++) #define pb(x) push_back(x) #define pf(x) push_front(x) #define st first #define nd second ll inf=1e9+7; ll mod=1e9+7; int main () { ios_base::sync_with_stdio(0); cin.tie(0); int n; string s; cin>>n; cin>>s; int tab[2]={0,0}; REP(i,n*8) tab[(int)s[i]-48]++; if(3*n>tab[1]){ cout<<"NIE"; return 0; } if(2*n>tab[0]){ cout<<"NIE"; return 0; } while(n>1){ if(tab[0]>tab[1]){ n--; cout<<'a'; tab[0]-=5; tab[1]-=3; } else if(tab[0]==tab[1]) { n--; cout<<'c'; tab[0]-=4; tab[1]-=4; } else if(tab[0]<tab[1]){ n--; tab[0]-=2; tab[1]-=6; cout<<'w'; } } int w=97; tab[1]-=3; int i=2; while(tab[1]>0){ tab[1]--; w+=i; i*=2; } cout<<(char)w; 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #include<bits/stdc++.h> using namespace std; typedef long long ll; #define SIZE(x) (int)x.size() #define REP(x,t) for(ll x=0; x<(t); x++) #define FOR(x,t) for(ll x=1; x<=(t); x++) #define pb(x) push_back(x) #define pf(x) push_front(x) #define st first #define nd second ll inf=1e9+7; ll mod=1e9+7; int main () { ios_base::sync_with_stdio(0); cin.tie(0); int n; string s; cin>>n; cin>>s; int tab[2]={0,0}; REP(i,n*8) tab[(int)s[i]-48]++; if(3*n>tab[1]){ cout<<"NIE"; return 0; } if(2*n>tab[0]){ cout<<"NIE"; return 0; } while(n>1){ if(tab[0]>tab[1]){ n--; cout<<'a'; tab[0]-=5; tab[1]-=3; } else if(tab[0]==tab[1]) { n--; cout<<'c'; tab[0]-=4; tab[1]-=4; } else if(tab[0]<tab[1]){ n--; tab[0]-=2; tab[1]-=6; cout<<'w'; } } int w=97; tab[1]-=3; int i=2; while(tab[1]>0){ tab[1]--; w+=i; i*=2; } cout<<(char)w; return 0; } |