83732024-01-15 09:02:36anonMexxcpp17Accepted 100/100112ms21516 KiB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long long ll;
int main() {
    FastIO;
    bool ok, same;
    ll i, j, rs, N;
    cin >> N;
    vector<ll> lucky(N);
    for(i = 0; i < N; i++)
        cin >> lucky[i];
    rs = lucky[0] - 1;
    ok = same = true;
    vector<ll> ans(N, 0);
    stack<ll> free_places;
    for(i = 1; i < N; i++) {
        if(lucky[i] == lucky[i - 1])
            continue;
        same = false;
        if(lucky[i] < lucky[i - 1] || ((lucky[i] - lucky[i - 1]) > (i - rs + ((ll) free_places.size())))) {
            ok = false;
            break;
        }
        for(j = 0; j < min(lucky[i] - lucky[i - 1], i - rs); j++)
            ans[i - j] = j + lucky[i - 1];
        while(j < i - rs)
            free_places.push(i - j++);
        while(j < lucky[i] - lucky[i - 1]) {
            ans[free_places.top()] = j++ + lucky[i - 1];
            free_places.pop();
        }
        rs = i;
    }
    if(same) {
        if(!lucky[0])
            fill(all(ans), 1);
        else if(lucky[0] > 1)
            ok = false;
    }
    else if(ok) {
        for(i = 0; i < N && !lucky[i] && !ans[i]; i++)
            ans[i] = lucky.back() + 1;
    }
    if(ok) {
        cout << "IGEN\n";
        for(const auto &x : ans)
            cout << x << ' ';
        cout << '\n';
    }
    else
        cout << "NEM\n";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1832 KiB
2Accepted3ms2028 KiB
subtask28/8
3Accepted3ms2232 KiB
4Accepted3ms2316 KiB
5Accepted3ms2316 KiB
6Accepted3ms2440 KiB
7Accepted3ms2656 KiB
8Accepted3ms2884 KiB
9Accepted3ms3108 KiB
10Accepted3ms3324 KiB
11Accepted3ms3552 KiB
subtask316/16
12Accepted2ms3620 KiB
13Accepted3ms3748 KiB
14Accepted3ms3856 KiB
15Accepted3ms3928 KiB
16Accepted3ms3904 KiB
subtask432/32
17Accepted4ms4276 KiB
18Accepted4ms4360 KiB
19Accepted4ms4352 KiB
20Accepted4ms4356 KiB
21Accepted4ms4356 KiB
22Accepted4ms4352 KiB
23Accepted3ms4364 KiB
24Accepted3ms4372 KiB
subtask544/44
25Accepted111ms20040 KiB
26Accepted109ms19740 KiB
27Accepted111ms19860 KiB
28Accepted108ms20116 KiB
29Accepted108ms20336 KiB
30Accepted111ms20168 KiB
31Accepted111ms20160 KiB
32Accepted111ms20216 KiB
33Accepted112ms20160 KiB
34Accepted112ms20148 KiB
35Accepted112ms20160 KiB
36Accepted68ms21180 KiB
37Accepted67ms21516 KiB