#if defined(EMBE_DEBUG) && !defined(NDEBUG) #include "embe-debug.hpp" #else #define LOG_INDENT(...) do {} while (false) #define LOG(...) do {} while (false) #define DUMP(...) do {} while (false) #endif #include <cassert> #include <iostream> #include <optional> #include <string> using namespace std; namespace { optional<string> solve(int n, int zeros, int ones) { assert(ones + zeros == 8 * n); if (zeros < 2 * n || ones < 3 * n) return {}; string res; res.reserve(n); while (n > 0) { int o = ones / n; assert(o >= 3); assert(o <= 6); char c = 'a' + (1 << (o - 2)) - 2; assert(c >= 'a' && c <= 'z'); assert(__builtin_popcount(c) == o); res.push_back(c); ones -= o; zeros -= 8 - o; --n; } assert(ones == 0); assert(zeros == 0); return res; } } int main() { iostream::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; int zeros = 0; int ones = 0; for (int i = 0; i < 8 * n; ++i) { char c; cin >> c; if (c == '0') ++zeros; else assert(c == '1'), ++ones; } auto res = solve(n, zeros, ones); if (!res) cout << "NIE" << endl; else cout << *res << endl; 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 | #if defined(EMBE_DEBUG) && !defined(NDEBUG) #include "embe-debug.hpp" #else #define LOG_INDENT(...) do {} while (false) #define LOG(...) do {} while (false) #define DUMP(...) do {} while (false) #endif #include <cassert> #include <iostream> #include <optional> #include <string> using namespace std; namespace { optional<string> solve(int n, int zeros, int ones) { assert(ones + zeros == 8 * n); if (zeros < 2 * n || ones < 3 * n) return {}; string res; res.reserve(n); while (n > 0) { int o = ones / n; assert(o >= 3); assert(o <= 6); char c = 'a' + (1 << (o - 2)) - 2; assert(c >= 'a' && c <= 'z'); assert(__builtin_popcount(c) == o); res.push_back(c); ones -= o; zeros -= 8 - o; --n; } assert(ones == 0); assert(zeros == 0); return res; } } int main() { iostream::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; int zeros = 0; int ones = 0; for (int i = 0; i < 8 * n; ++i) { char c; cin >> c; if (c == '0') ++zeros; else assert(c == '1'), ++ones; } auto res = solve(n, zeros, ones); if (!res) cout << "NIE" << endl; else cout << *res << endl; return 0; } |