#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vvc = vector<vc>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vll = vector<ll>;
using vull = vector<ull>;
using vvll = vector<vll>;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define f first
#define s second
#define pb emplace_back
#define rep(i, begin, end) for(auto i = (begin); i <= (end); ++i)
#define repr(i, begin, end) for(auto i = (begin); i >= (end); --i)
#define bend(X) X.begin(), X.end()
#ifdef LOCAL
#define deb(...) cout << #__VA_ARGS__ << " = " << __VA_ARGS__ << endl
#define say(...) cout << __VA_ARGS__ << endl
#else
#define deb(x)
#define say(x)
#define endl '\n'
#endif
constexpr int INF = 1e9+1e7;
constexpr ll INFl = INF;
constexpr ll INFll = 1e18+1e16;
void print() { cout << '\n'; }
template <typename T, typename... Args> void print(T x, Args... args) { cout << x << ' '; print(args...); }
template <typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2> x) { os << x.f << ' ' << x.s; return os; }
template <typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& x) { is >> x.f >> x.s; return is; }
template <typename Ch, typename Tr, typename T> ostream& operator<<(basic_ostream<Ch,Tr>& os, T x) { for(auto i : x) os << i << ' '; return os; }
template <typename T> istream& operator>>(istream& is, vector<T>& x) { for(T& i : x) is >> i; return is; }
template <typename T1, typename T2> pair<T1,T2> operator+(const pair<T1,T2>& A, const pair<T1,T2>& B) { return {A.f+B.f, A.s+B.s}; }
template <typename T1, typename T2> pair<T1,T2> operator-(const pair<T1,T2>& A, const pair<T1,T2>& B) { return {A.f-B.f, A.s-B.s}; }
template <typename T1, typename T2> pair<T1,T2>& operator+=(pair<T1,T2>& A, const pair<T1,T2>& B) { A.f += B.f; A.s += B.s; return A; }
template <typename T1, typename T2> pair<T1,T2>& operator-=(pair<T1,T2>& A, const pair<T1,T2>& B) { A.f -= B.f; A.s -= B.s; return A; }
template <typename T1, typename T2> pair<T1,T2> operator-(const pair<T1,T2>& A) { return {-A.f, -A.s}; }
template <typename T1, typename T2> bool maxe(T1& A, const T2& B) { if(B>A) { A=B; return 1; } return 0; }
template <typename T1, typename T2> bool mine(T1& A, const T2& B) { if(B<A) { A=B; return 1; } return 0; }
class Nic{} nic;
template <typename T> Nic operator<<(Nic, T) { return nic; }
Nic operator<<(ostream&, Nic) { return nic; }
//////////////////////////////////////////////////
int n;
int cnt[2];
string R;
void add(int a, int b) {
cnt[0] -= a;
cnt[1] -= b;
if (cnt[0] < 0 || cnt[1] < 0) {
cout << "NIE\n";
exit(0);
}
}
void add41() { add(4,1); R += 'a'; }
void add32() { add(3,2); R += 'c'; }
void add23() { add(2,3); R += 'g'; }
void add14() { add(1,4); R += 'o'; }
auto solve() {
cin >> n;
rep (i, 1, 8*n) {
char x;
cin >> x;
cnt[x-'0']++;
}
add(n, 2*n);
while (cnt[0]+3 <= cnt[1]) add14();
while (cnt[1]+3 <= cnt[0]) add41();
while (cnt[0] > cnt[1]) add32();
while (cnt[1] > cnt[0]) add23();
while (cnt[0] > 0) { add32(); add23(); }
return R;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int noOfTests = 1;
//cin >> noOfTests;
while(noOfTests --> 0)
cout << solve() << '\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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair<int,int>; using pll = pair<ll,ll>; using vi = vector<int>; using vb = vector<bool>; using vc = vector<char>; using vvc = vector<vc>; using vvi = vector<vi>; using vvb = vector<vb>; using vpii = vector<pii>; using vpll = vector<pll>; using vll = vector<ll>; using vull = vector<ull>; using vvll = vector<vll>; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define f first #define s second #define pb emplace_back #define rep(i, begin, end) for(auto i = (begin); i <= (end); ++i) #define repr(i, begin, end) for(auto i = (begin); i >= (end); --i) #define bend(X) X.begin(), X.end() #ifdef LOCAL #define deb(...) cout << #__VA_ARGS__ << " = " << __VA_ARGS__ << endl #define say(...) cout << __VA_ARGS__ << endl #else #define deb(x) #define say(x) #define endl '\n' #endif constexpr int INF = 1e9+1e7; constexpr ll INFl = INF; constexpr ll INFll = 1e18+1e16; void print() { cout << '\n'; } template <typename T, typename... Args> void print(T x, Args... args) { cout << x << ' '; print(args...); } template <typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2> x) { os << x.f << ' ' << x.s; return os; } template <typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& x) { is >> x.f >> x.s; return is; } template <typename Ch, typename Tr, typename T> ostream& operator<<(basic_ostream<Ch,Tr>& os, T x) { for(auto i : x) os << i << ' '; return os; } template <typename T> istream& operator>>(istream& is, vector<T>& x) { for(T& i : x) is >> i; return is; } template <typename T1, typename T2> pair<T1,T2> operator+(const pair<T1,T2>& A, const pair<T1,T2>& B) { return {A.f+B.f, A.s+B.s}; } template <typename T1, typename T2> pair<T1,T2> operator-(const pair<T1,T2>& A, const pair<T1,T2>& B) { return {A.f-B.f, A.s-B.s}; } template <typename T1, typename T2> pair<T1,T2>& operator+=(pair<T1,T2>& A, const pair<T1,T2>& B) { A.f += B.f; A.s += B.s; return A; } template <typename T1, typename T2> pair<T1,T2>& operator-=(pair<T1,T2>& A, const pair<T1,T2>& B) { A.f -= B.f; A.s -= B.s; return A; } template <typename T1, typename T2> pair<T1,T2> operator-(const pair<T1,T2>& A) { return {-A.f, -A.s}; } template <typename T1, typename T2> bool maxe(T1& A, const T2& B) { if(B>A) { A=B; return 1; } return 0; } template <typename T1, typename T2> bool mine(T1& A, const T2& B) { if(B<A) { A=B; return 1; } return 0; } class Nic{} nic; template <typename T> Nic operator<<(Nic, T) { return nic; } Nic operator<<(ostream&, Nic) { return nic; } ////////////////////////////////////////////////// int n; int cnt[2]; string R; void add(int a, int b) { cnt[0] -= a; cnt[1] -= b; if (cnt[0] < 0 || cnt[1] < 0) { cout << "NIE\n"; exit(0); } } void add41() { add(4,1); R += 'a'; } void add32() { add(3,2); R += 'c'; } void add23() { add(2,3); R += 'g'; } void add14() { add(1,4); R += 'o'; } auto solve() { cin >> n; rep (i, 1, 8*n) { char x; cin >> x; cnt[x-'0']++; } add(n, 2*n); while (cnt[0]+3 <= cnt[1]) add14(); while (cnt[1]+3 <= cnt[0]) add41(); while (cnt[0] > cnt[1]) add32(); while (cnt[1] > cnt[0]) add23(); while (cnt[0] > 0) { add32(); add23(); } return R; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int noOfTests = 1; //cin >> noOfTests; while(noOfTests --> 0) cout << solve() << '\n'; return 0; } |
English