73162024-01-06 22:12:29anonMexxcpp17Partially correct 94/100116ms21736 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;
    }
    if(ok) {
        cout << "IGEN\n";
        for(const auto &x : ans)
            cout << x << ' ';
        cout << '\n';
    }
    else
        cout << "NEM\n";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2060 KiB
subtask22/8
3Accepted3ms2268 KiB
4Partially correct3ms2588 KiB
5Accepted3ms2716 KiB
6Partially correct3ms2684 KiB
7Accepted3ms2892 KiB
8Accepted3ms3100 KiB
9Accepted3ms3312 KiB
10Accepted3ms3356 KiB
11Accepted3ms3420 KiB
subtask316/16
12Accepted3ms3640 KiB
13Accepted3ms3684 KiB
14Accepted3ms3796 KiB
15Accepted3ms3924 KiB
16Accepted3ms3776 KiB
subtask432/32
17Accepted4ms4020 KiB
18Accepted4ms4144 KiB
19Accepted4ms4376 KiB
20Accepted4ms4356 KiB
21Accepted4ms4556 KiB
22Accepted4ms4640 KiB
23Accepted4ms5052 KiB
24Accepted3ms5172 KiB
subtask544/44
25Accepted112ms20920 KiB
26Accepted114ms20512 KiB
27Accepted114ms20380 KiB
28Accepted112ms20496 KiB
29Accepted115ms20484 KiB
30Accepted114ms20368 KiB
31Accepted112ms20412 KiB
32Accepted112ms20384 KiB
33Accepted115ms20380 KiB
34Accepted114ms20528 KiB
35Accepted116ms20384 KiB
36Accepted71ms21416 KiB
37Accepted71ms21736 KiB