#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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1832 KiB | ||||
2 | Accepted | 3ms | 2028 KiB | ||||
subtask2 | 8/8 | ||||||
3 | Accepted | 3ms | 2232 KiB | ||||
4 | Accepted | 3ms | 2316 KiB | ||||
5 | Accepted | 3ms | 2316 KiB | ||||
6 | Accepted | 3ms | 2440 KiB | ||||
7 | Accepted | 3ms | 2656 KiB | ||||
8 | Accepted | 3ms | 2884 KiB | ||||
9 | Accepted | 3ms | 3108 KiB | ||||
10 | Accepted | 3ms | 3324 KiB | ||||
11 | Accepted | 3ms | 3552 KiB | ||||
subtask3 | 16/16 | ||||||
12 | Accepted | 2ms | 3620 KiB | ||||
13 | Accepted | 3ms | 3748 KiB | ||||
14 | Accepted | 3ms | 3856 KiB | ||||
15 | Accepted | 3ms | 3928 KiB | ||||
16 | Accepted | 3ms | 3904 KiB | ||||
subtask4 | 32/32 | ||||||
17 | Accepted | 4ms | 4276 KiB | ||||
18 | Accepted | 4ms | 4360 KiB | ||||
19 | Accepted | 4ms | 4352 KiB | ||||
20 | Accepted | 4ms | 4356 KiB | ||||
21 | Accepted | 4ms | 4356 KiB | ||||
22 | Accepted | 4ms | 4352 KiB | ||||
23 | Accepted | 3ms | 4364 KiB | ||||
24 | Accepted | 3ms | 4372 KiB | ||||
subtask5 | 44/44 | ||||||
25 | Accepted | 111ms | 20040 KiB | ||||
26 | Accepted | 109ms | 19740 KiB | ||||
27 | Accepted | 111ms | 19860 KiB | ||||
28 | Accepted | 108ms | 20116 KiB | ||||
29 | Accepted | 108ms | 20336 KiB | ||||
30 | Accepted | 111ms | 20168 KiB | ||||
31 | Accepted | 111ms | 20160 KiB | ||||
32 | Accepted | 111ms | 20216 KiB | ||||
33 | Accepted | 112ms | 20160 KiB | ||||
34 | Accepted | 112ms | 20148 KiB | ||||
35 | Accepted | 112ms | 20160 KiB | ||||
36 | Accepted | 68ms | 21180 KiB | ||||
37 | Accepted | 67ms | 21516 KiB |