#include <bits/stdc++.h> using namespace std; typedef intmax_t I; constexpr I inf = 1e18; typedef pair<I, I> II; typedef double F; #define debug_printable(template_thingies, type, start, printer, stop) \ template <template_thingies> \ ostream &operator<<(ostream &o, const type &v) { \ for (auto i = (o << start, v.begin()); i != v.end(); ++i) \ (i != v.begin() && (o << ", ")), o << printer; \ return o << stop; \ } #define comma , debug_printable(typename T, vector<T>, "[", *i, "]"); debug_printable(typename T comma size_t N, array<T comma N>, "<", *i, ">"); debug_printable(typename T, set<T>, "{", *i, "}"); debug_printable(typename T comma typename U, map<T comma U>, "{", i->first << ": " << i->second, "}"); template <typename T, typename U> ostream &operator<<(ostream &o, pair<T, U> p) { return o << "(" << p.first << ", " << p.second << ")"; } int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); I n; cin >> n; I x = 0; string s; cin >> s; for (I i = 0; i < 8 * n; ++i) if (s[i] == '1') ++x; // vector<char> example(9); // for (char c = 'z'; c >= 'a'; --c) example[__builtin_popcount(c)] = c; // x -= 3 * n; I d = (x - 3 * n) / 3; I c = ((x - 3 * n) % 3 == 2 ? 1 : 0); I b = ((x - 3 * n) % 3 == 1 ? 1 : 0); I a = n - d - c - b; bool ok = (b + 2 * c + 3 * d == x - 3 * n) && (3 * a + 4 * b + 5 * c + 6 * d == x) && (a + b + c + d == n) && (a >= 0 && b >= 0 && c >= 0 && d >= 0); // cout << b + 2 * c + 3 * d << " == " << x - 3 * n << "\n"; // cout << 3 * a + 4 * b + 5 * c + 6 * d << " == " << x << "\n"; // cout << a + b + c + d << " == " << n << "\n"; // cout << a << " " << b << " " << c << " " << d << endl; // cout << example << " " << x << endl; if (ok) { cout << string(a, 'a') << string(b, 'c') << string(c, 'g') << string(d, 'o') << "\n"; } else { cout << "NIE\n"; } // zeroes -= n; // ones -= 2 * n; }
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 | #include <bits/stdc++.h> using namespace std; typedef intmax_t I; constexpr I inf = 1e18; typedef pair<I, I> II; typedef double F; #define debug_printable(template_thingies, type, start, printer, stop) \ template <template_thingies> \ ostream &operator<<(ostream &o, const type &v) { \ for (auto i = (o << start, v.begin()); i != v.end(); ++i) \ (i != v.begin() && (o << ", ")), o << printer; \ return o << stop; \ } #define comma , debug_printable(typename T, vector<T>, "[", *i, "]"); debug_printable(typename T comma size_t N, array<T comma N>, "<", *i, ">"); debug_printable(typename T, set<T>, "{", *i, "}"); debug_printable(typename T comma typename U, map<T comma U>, "{", i->first << ": " << i->second, "}"); template <typename T, typename U> ostream &operator<<(ostream &o, pair<T, U> p) { return o << "(" << p.first << ", " << p.second << ")"; } int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); I n; cin >> n; I x = 0; string s; cin >> s; for (I i = 0; i < 8 * n; ++i) if (s[i] == '1') ++x; // vector<char> example(9); // for (char c = 'z'; c >= 'a'; --c) example[__builtin_popcount(c)] = c; // x -= 3 * n; I d = (x - 3 * n) / 3; I c = ((x - 3 * n) % 3 == 2 ? 1 : 0); I b = ((x - 3 * n) % 3 == 1 ? 1 : 0); I a = n - d - c - b; bool ok = (b + 2 * c + 3 * d == x - 3 * n) && (3 * a + 4 * b + 5 * c + 6 * d == x) && (a + b + c + d == n) && (a >= 0 && b >= 0 && c >= 0 && d >= 0); // cout << b + 2 * c + 3 * d << " == " << x - 3 * n << "\n"; // cout << 3 * a + 4 * b + 5 * c + 6 * d << " == " << x << "\n"; // cout << a + b + c + d << " == " << n << "\n"; // cout << a << " " << b << " " << c << " " << d << endl; // cout << example << " " << x << endl; if (ok) { cout << string(a, 'a') << string(b, 'c') << string(c, 'g') << string(d, 'o') << "\n"; } else { cout << "NIE\n"; } // zeroes -= n; // ones -= 2 * n; } |