#include <bits/stdc++.h> using namespace std; const int M_SIZE = 5e5+1; char n_bit_letter[9]; int n; string s; char res[M_SIZE]; int main() { for(int i=1; i<=26; i++){ n_bit_letter[ __builtin_popcountll(i+96)] = char(96+i); } cin>>n; cin>>s; int sum = 0; for(int i=0; i<s.size();i++){ if(s[i] == '1') sum++; } if(sum > 6 * n || sum < 3 * n){ cout<<"NIE"; return 0; } for(int i=n; i>=1; i--){ if(sum >= 3 * i + 3){ res[i-1] = n_bit_letter[6]; sum -= 6; } else{ int nr = 3 + sum - 3 * i; res[i-1] = n_bit_letter[nr]; sum -= nr; } } for(size_t i=0; i<n; i++) cout<<res[i]; 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 | #include <bits/stdc++.h> using namespace std; const int M_SIZE = 5e5+1; char n_bit_letter[9]; int n; string s; char res[M_SIZE]; int main() { for(int i=1; i<=26; i++){ n_bit_letter[ __builtin_popcountll(i+96)] = char(96+i); } cin>>n; cin>>s; int sum = 0; for(int i=0; i<s.size();i++){ if(s[i] == '1') sum++; } if(sum > 6 * n || sum < 3 * n){ cout<<"NIE"; return 0; } for(int i=n; i>=1; i--){ if(sum >= 3 * i + 3){ res[i-1] = n_bit_letter[6]; sum -= 6; } else{ int nr = 3 + sum - 3 * i; res[i-1] = n_bit_letter[nr]; sum -= nr; } } for(size_t i=0; i<n; i++) cout<<res[i]; return 0; } |