#include <iostream> #include <bitset> #define MAX 500001 using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(false); int n; string bits; cin >> n; cin >> bits; int zeros = 0; int ones = 0; for (const auto &bit: bits) { if (bit == '0') zeros += 1; if (bit == '1') ones += 1; } // cout << bits << endl; // cout << zeros << endl << ones << endl; if (zeros < n * 2 || zeros > n * 5 || ones < n * 3 || ones > n * 6) { cout << "NIE"; } else { while (zeros != 0 || ones != 0) { if (zeros == 3 && ones == 5) { cout << 's'; zeros -= 3; ones -= 5; } else if (zeros > ones) { cout << 'a'; zeros -= 5; ones -= 3; } else if (ones > zeros) { cout << 'w'; zeros -= 2; ones -= 6; } else { cout << 'c'; zeros -= 4; ones -= 4; } } } 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 | #include <iostream> #include <bitset> #define MAX 500001 using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(false); int n; string bits; cin >> n; cin >> bits; int zeros = 0; int ones = 0; for (const auto &bit: bits) { if (bit == '0') zeros += 1; if (bit == '1') ones += 1; } // cout << bits << endl; // cout << zeros << endl << ones << endl; if (zeros < n * 2 || zeros > n * 5 || ones < n * 3 || ones > n * 6) { cout << "NIE"; } else { while (zeros != 0 || ones != 0) { if (zeros == 3 && ones == 5) { cout << 's'; zeros -= 3; ones -= 5; } else if (zeros > ones) { cout << 'a'; zeros -= 5; ones -= 3; } else if (ones > zeros) { cout << 'w'; zeros -= 2; ones -= 6; } else { cout << 'c'; zeros -= 4; ones -= 4; } } } return 0; } |