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
/*
 * zak.cpp
 *
 *  Created on: Dec 8, 2021
 *      Author: A.Mulawa
 */

#include <bits/stdc++.h>

using namespace std;

int main(int argc, char **argv)
{
    int l[] = {'a', 'c', 'g', 'w'};

    int n;
    scanf("%d", &n);
    char str[8 * 500000 + 1];
    int tt[500000] = {0};
    scanf("%s", &str[0]);

    int lbr = 0;
    lbr = 0;
    for (int i = 0; i < n; i++)
    {
        int lb = 0 + lbr;
        for (int j = 0; j < 8; j++)
        {
            if (str[i * 8 + j] == '1')
            {
                lb++;
            }
        }
        int t = max(3, min(lb, 6));
        lbr = lb - t;
        tt[i] = t;
    }

    bool k = true;
    while (lbr<0 && k)
    {
        k = false;
        for (int i = 0; i < n ; i++)
        {
            if (tt[i] > 3)
            {
              tt[i] = tt[i]-1;
              lbr++;
              k = true;
              if(lbr >= 0)
                  break;
            }
        }
    }

    if (lbr < 0)
        cout << "NIE";
    else
    {
        for (int i = 0; i < n; i++)
          cout << char(l[tt[i]-3]);
    }

    return 0;
};