61172023-11-01 18:49:41horvathabelMexxcpp17Accepted 100/100252ms24768 KiB
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> ans(n,-1);
    vector<pair<bool,int>> szm={{0,0}};
    int x;
    cin>>x;
    vector<int> a={x};
    bool mego=true;
    for (int i=1; i<n;i++){

        szm.push_back({false,i});
        int x;
        cin>>x;
        a.push_back(x);

        if (x>i+1 || a[i]<a[i-1]){
            cout<<"NEM\n";
            return 0;
        }
        if (a[i]!=a[i-1]){
            ans[i]=a[i-1];
            if (szm.size()>=a[i-1]){
                szm[a[i-1]].first=true;
            }
            else{
                mego=false;
            }
        }
    }

    szm.push_back({false,n});
    szm[a[n-1]].first=true;
    if (!mego){
        cout<<"NEM\n";
        return 0;
    }
    if (a[0]>1){
        cout<<"NEM\n";
        return 0;
    }
    for (int i=n-1;i>=0;i--){
        if (ans[i]==-1){
            while(!szm.empty() && szm[szm.size()-1].first==1){
                szm.pop_back();
            }
            ans[i]=szm[szm.size()-1].second;
            szm.pop_back();
        }
    }
    cout<<"IGEN\n";
    for (int x:ans) cout<<x<<" ";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1684 KiB
2Accepted3ms1940 KiB
subtask28/8
3Accepted3ms2168 KiB
4Accepted3ms2356 KiB
5Accepted3ms2600 KiB
6Accepted3ms2816 KiB
7Accepted3ms2944 KiB
8Accepted2ms3160 KiB
9Accepted3ms3328 KiB
10Accepted3ms3548 KiB
11Accepted3ms3632 KiB
subtask316/16
12Accepted3ms3752 KiB
13Accepted2ms3840 KiB
14Accepted2ms3956 KiB
15Accepted2ms3844 KiB
16Accepted3ms3960 KiB
subtask432/32
17Accepted4ms4232 KiB
18Accepted4ms4236 KiB
19Accepted4ms4232 KiB
20Accepted6ms4356 KiB
21Accepted4ms4440 KiB
22Accepted4ms4444 KiB
23Accepted4ms4428 KiB
24Accepted4ms4548 KiB
subtask544/44
25Accepted246ms23896 KiB
26Accepted250ms23908 KiB
27Accepted246ms23900 KiB
28Accepted245ms23924 KiB
29Accepted246ms24016 KiB
30Accepted248ms24068 KiB
31Accepted246ms24184 KiB
32Accepted248ms24352 KiB
33Accepted246ms24540 KiB
34Accepted246ms24768 KiB
35Accepted252ms24724 KiB
36Accepted143ms22172 KiB
37Accepted150ms22556 KiB