73152024-01-06 21:41:44anonMexxcpp17Partially correct 94/100118ms21792 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] || ((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
2Accepted3ms2064 KiB
subtask22/8
3Accepted3ms2228 KiB
4Partially correct3ms2440 KiB
5Accepted3ms2656 KiB
6Partially correct3ms2740 KiB
7Accepted2ms2748 KiB
8Accepted3ms2740 KiB
9Accepted3ms2868 KiB
10Accepted3ms3084 KiB
11Accepted2ms3156 KiB
subtask316/16
12Accepted2ms3160 KiB
13Accepted3ms3164 KiB
14Accepted3ms3292 KiB
15Accepted3ms3508 KiB
16Accepted3ms3724 KiB
subtask432/32
17Accepted4ms4052 KiB
18Accepted4ms4052 KiB
19Accepted4ms4048 KiB
20Accepted4ms4200 KiB
21Accepted4ms4116 KiB
22Accepted4ms4116 KiB
23Accepted4ms4124 KiB
24Accepted3ms4236 KiB
subtask544/44
25Accepted112ms19928 KiB
26Accepted115ms19788 KiB
27Accepted112ms19832 KiB
28Accepted112ms19728 KiB
29Accepted115ms19916 KiB
30Accepted115ms20100 KiB
31Accepted112ms20252 KiB
32Accepted112ms20128 KiB
33Accepted114ms20252 KiB
34Accepted115ms20164 KiB
35Accepted118ms20176 KiB
36Accepted71ms21192 KiB
37Accepted71ms21792 KiB