73142024-01-06 21:06:56anonMexxcpp17Partially correct 94/100115ms21632 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 = -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] > i - rs + 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) {
        switch(lucky[0]) {
            case 0:
                ok = true;
                fill(all(ans), 1);
                break;
            case 1:
                ok = true;
                break;
            default:
                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
1Accepted3ms1860 KiB
2Accepted3ms2024 KiB
subtask22/8
3Accepted3ms2236 KiB
4Partially correct3ms2448 KiB
5Accepted3ms2668 KiB
6Partially correct3ms3016 KiB
7Accepted3ms3016 KiB
8Accepted3ms3096 KiB
9Accepted2ms3204 KiB
10Accepted3ms3308 KiB
11Accepted3ms3164 KiB
subtask316/16
12Accepted3ms3168 KiB
13Accepted2ms3164 KiB
14Accepted3ms3164 KiB
15Accepted3ms3288 KiB
16Accepted3ms3504 KiB
subtask432/32
17Accepted4ms3832 KiB
18Accepted4ms3832 KiB
19Accepted4ms3968 KiB
20Accepted4ms3832 KiB
21Accepted4ms4048 KiB
22Accepted4ms4192 KiB
23Accepted4ms4140 KiB
24Accepted3ms4132 KiB
subtask544/44
25Accepted114ms20028 KiB
26Accepted114ms19912 KiB
27Accepted112ms19856 KiB
28Accepted112ms19848 KiB
29Accepted112ms19940 KiB
30Accepted112ms19848 KiB
31Accepted112ms19848 KiB
32Accepted114ms20064 KiB
33Accepted112ms20076 KiB
34Accepted115ms20136 KiB
35Accepted115ms20204 KiB
36Accepted68ms21360 KiB
37Accepted65ms21632 KiB