53942023-05-09 14:11:25mraronMexxcpp17Accepted 100/100116ms20168 KiB
#include<bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;++i) {
        cin>>a[i];
    }
    bool ok=true;
    for(int i=0;i<n;++i) {
        ok&=i==0||a[i-1]<=a[i];
        ok&=a[i]<=i+1;
    }
    
    cerr<<ok<<"\n";
    if(!ok) {
        cout<<"NEM\n";
        return 0;
    }

    a.insert(a.begin(), 0);
    int mx=*max_element(a.begin(), a.end());

    vector<int> had(2*n);
    vector<int> b(n+1,-1);
    for(int i=1;i<=n;++i) {
        if(a[i-1]!=a[i]) {
            b[i]=a[i-1];
            had[b[i]]=1;
        }
    }
    
    int curr=0;
    for(int i=1;i<=n;++i) {
        if(b[i]==-1) {
            while(had[curr] || curr==mx) curr++;
            b[i]=curr;
            had[curr]=1;
        }
    }

    for(int i=1;i<=n;) {
        int j=i;
        while(j<=n && a[i]==a[j]) j++;
        if(i+1<j) {
            reverse(b.begin()+i+1, b.begin()+j);
        }
        i=j;
    }

    cout<<"IGEN\n";
    for(int i=1;i<=n;++i) cout<<b[i]<<" ";
    cout<<"\n";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1700 KiB
2Accepted3ms1928 KiB
subtask28/8
3Accepted3ms2136 KiB
4Accepted3ms2348 KiB
5Accepted3ms2572 KiB
6Accepted3ms2784 KiB
7Accepted3ms2872 KiB
8Accepted3ms2864 KiB
9Accepted3ms2996 KiB
10Accepted2ms3076 KiB
11Accepted3ms3204 KiB
subtask316/16
12Accepted3ms3292 KiB
13Accepted3ms3296 KiB
14Accepted3ms3292 KiB
15Accepted3ms3416 KiB
16Accepted2ms3500 KiB
subtask432/32
17Accepted4ms4076 KiB
18Accepted4ms3956 KiB
19Accepted4ms4032 KiB
20Accepted4ms4384 KiB
21Accepted4ms4544 KiB
22Accepted4ms4664 KiB
23Accepted3ms4308 KiB
24Accepted3ms4196 KiB
subtask544/44
25Accepted108ms19884 KiB
26Accepted109ms19876 KiB
27Accepted112ms20128 KiB
28Accepted112ms20168 KiB
29Accepted109ms20056 KiB
30Accepted109ms20060 KiB
31Accepted111ms20012 KiB
32Accepted111ms20012 KiB
33Accepted112ms20012 KiB
34Accepted112ms20008 KiB
35Accepted116ms20008 KiB
36Accepted56ms8332 KiB
37Accepted56ms8180 KiB