#include<bits/stdc++.h> #define ST first #define ND second #define ll long long #define ld long double #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " using namespace std; const ll INF = 1e9 + 9; const ll MOD = 1e9 + 7; const long long LINF = (ll)1e18 + 3; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; string s; cin >> s; int ones = 0,zeros = 0; for(int i = 0; i < 8*n; i++) if(s[i] == '1') ones++; zeros = 8*n - ones; vector<char> xd = {'a','c','g','w'}; string ans = ""; for(int i = 0; i < n; i++) ans += xd.back(); ones -= 6 * n; zeros -= 2 * n; for(int i = 0; i < n; i++){ if(ones + 3 <= 0){ ans[i] = xd[0]; ones += 3; zeros -= 3; } else if(ones + 2 <= 0){ ans[i] = xd[1]; ones += 2; zeros -= 2; } else if(ones + 1 <= 0){ ans[i] = xd[2]; ones += 1; zeros -= 1; } else { break; } } if(ones == 0 && zeros == 0){ cout << ans << "\n"; } else { cout << "NIE\n"; } 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 | #include<bits/stdc++.h> #define ST first #define ND second #define ll long long #define ld long double #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " using namespace std; const ll INF = 1e9 + 9; const ll MOD = 1e9 + 7; const long long LINF = (ll)1e18 + 3; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; string s; cin >> s; int ones = 0,zeros = 0; for(int i = 0; i < 8*n; i++) if(s[i] == '1') ones++; zeros = 8*n - ones; vector<char> xd = {'a','c','g','w'}; string ans = ""; for(int i = 0; i < n; i++) ans += xd.back(); ones -= 6 * n; zeros -= 2 * n; for(int i = 0; i < n; i++){ if(ones + 3 <= 0){ ans[i] = xd[0]; ones += 3; zeros -= 3; } else if(ones + 2 <= 0){ ans[i] = xd[1]; ones += 2; zeros -= 2; } else if(ones + 1 <= 0){ ans[i] = xd[2]; ones += 1; zeros -= 1; } else { break; } } if(ones == 0 && zeros == 0){ cout << ans << "\n"; } else { cout << "NIE\n"; } return 0; } |