#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define pb push_back #define debug(x) cout << #x << " " << x << endl #define all(x) x.begin(),x.end() #define ll long long #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define vll vector<ll> #define vvll vector<vll> #define ld long double #define ull unsigned long long #define vull vector<ull> #define fi first #define se second #define PII pair<int,int> #define vPII vector<PII> #define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());} #define int128 __int128 int main() { ios::sync_with_stdio(false); cin.tie(nullptr); // cout << setprecision(16) << fixed; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int tt = 1; // cin >> tt; while(tt--) { int n; cin >> n; string s; cin >> s; vi cnt(2,0); rep(i,8*n) cnt[s[i]=='1']++; int mini = 3*n; int maks = 6*n; if(mini > cnt[1] or cnt[1] > maks){ cout << "NIE"; return 0; } int i = n; string ans; while(i and (i-1)*3 <= cnt[1] - 6){ ans += 'w'; cnt[1]-=6; i--; } if(i and (i-1)*3 == cnt[1] - 5){ i--; ans += 's'; cnt[1] -= 5; } if(i and (i-1)*3 == cnt[1] - 4){ i--; ans += 'q'; cnt[1] -= 4; } while(i){ ans += 'a'; i--; cnt[1] -= 3; } assert(cnt[1] == 0); cout << ans; } }
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 68 69 | #include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define pb push_back #define debug(x) cout << #x << " " << x << endl #define all(x) x.begin(),x.end() #define ll long long #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define vll vector<ll> #define vvll vector<vll> #define ld long double #define ull unsigned long long #define vull vector<ull> #define fi first #define se second #define PII pair<int,int> #define vPII vector<PII> #define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());} #define int128 __int128 int main() { ios::sync_with_stdio(false); cin.tie(nullptr); // cout << setprecision(16) << fixed; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int tt = 1; // cin >> tt; while(tt--) { int n; cin >> n; string s; cin >> s; vi cnt(2,0); rep(i,8*n) cnt[s[i]=='1']++; int mini = 3*n; int maks = 6*n; if(mini > cnt[1] or cnt[1] > maks){ cout << "NIE"; return 0; } int i = n; string ans; while(i and (i-1)*3 <= cnt[1] - 6){ ans += 'w'; cnt[1]-=6; i--; } if(i and (i-1)*3 == cnt[1] - 5){ i--; ans += 's'; cnt[1] -= 5; } if(i and (i-1)*3 == cnt[1] - 4){ i--; ans += 'q'; cnt[1] -= 4; } while(i){ ans += 'a'; i--; cnt[1] -= 3; } assert(cnt[1] == 0); cout << ans; } } |