#pragma GCC optimize("Ofast,inline")
#pragma GCC target("bmi,bmi2,lzcnt,popcnt")
#pragma GCC target("avx,avx2,f16c,fma,sse3,ssse3,sse4.1,sse4.2")
#include <cstdio>
int n, cnt[2];
inline char gc() {
static char buf[1 << 16];
static size_t pos, len;
if(pos >= len) pos = 0, len = fread(buf, 1, sizeof(buf), stdin);
return buf[pos++];
}
inline int rd() {
int a, c;
while((a = gc()) < 40);
while((c = gc()) > 47) a = a * 10 + c - 480;
return a - 48;
}
int main() {
n = rd();
for(int i = 0; i < 8 * n; i++)
cnt[gc() - '0']++;
if(cnt[1] < 3 * n || 6 * n < cnt[1]) {
printf("NIE\n");
return 0;
}
while(n > 0) {
n--;
if(3 * n <= cnt[1] - 3 && cnt[1] - 3 <= 6 * n) {
printf("a");
cnt[1] -= 3;
}
else
if(3 * n <= cnt[1] - 4 && cnt[1] - 4 <= 6 * n) {
printf("c");
cnt[1] -= 4;
}
else
if(3 * n <= cnt[1] - 5 && cnt[1] - 5 <= 6 * n) {
printf("g");
cnt[1] -= 5;
}
else
if(3 * n <= cnt[1] - 6 && cnt[1] - 6 <= 6 * n) {
printf("o");
cnt[1] -= 6;
}
}
}
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 | #pragma GCC optimize("Ofast,inline") #pragma GCC target("bmi,bmi2,lzcnt,popcnt") #pragma GCC target("avx,avx2,f16c,fma,sse3,ssse3,sse4.1,sse4.2") #include <cstdio> int n, cnt[2]; inline char gc() { static char buf[1 << 16]; static size_t pos, len; if(pos >= len) pos = 0, len = fread(buf, 1, sizeof(buf), stdin); return buf[pos++]; } inline int rd() { int a, c; while((a = gc()) < 40); while((c = gc()) > 47) a = a * 10 + c - 480; return a - 48; } int main() { n = rd(); for(int i = 0; i < 8 * n; i++) cnt[gc() - '0']++; if(cnt[1] < 3 * n || 6 * n < cnt[1]) { printf("NIE\n"); return 0; } while(n > 0) { n--; if(3 * n <= cnt[1] - 3 && cnt[1] - 3 <= 6 * n) { printf("a"); cnt[1] -= 3; } else if(3 * n <= cnt[1] - 4 && cnt[1] - 4 <= 6 * n) { printf("c"); cnt[1] -= 4; } else if(3 * n <= cnt[1] - 5 && cnt[1] - 5 <= 6 * n) { printf("g"); cnt[1] -= 5; } else if(3 * n <= cnt[1] - 6 && cnt[1] - 6 <= 6 * n) { printf("o"); cnt[1] -= 6; } } } |
English