48252023-03-31 12:52:38csaron71Kombináció (50)cpp17Runtime error 41/504ms3672 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> van(n+1, 0);
    vector<int> v(n+1);
    for (int i=0; i<m; i++) {
        int x;
        cin >> x;
        van[x]=1;
        v[i]=x;
    }
    
    bool ell=true;
    for (int i=0; i<m; i++) {
      if (v[i]!=i+1) {
        ell=false;
      }
    }
    
    if (ell==true) {
      for (int i=n-m+1; i<=n; i++) {
        cout << i << " ";
      }
      cout << "\n";
    }
    else {
        int masik=-1, hol=m;
        while (masik==-1) {
            hol--;
            if (v[hol]>0 && van[v[hol]-1]==0) {
                masik=v[hol]-1;
            }
        }

        int b=0;
        while (b<hol) {
            cout << v[b]  << " ";
            b++;
        }
        cout << masik << " ";
        for (int i=n-(m-hol)+2; i<=n; i++) {
            cout << i << " ";
        }
        cout << "\n";
    }
    
    bool masik=true;
    for (int i=m-n+1; i<=n; i++) {
      if (v[i]!=i) {
        masik=false;
      }
    }
    
    if (masik==true) {
        for (int i=0; i<m; i++) {
          cout << i+1 << " ";
        }
        cout << "\n";
        return 0;
    }

    int uj=-1, epp=m;
    while (uj==-1) {
        epp--;
        if (v[epp]<n && van[v[epp]+1]==0) {
            uj=v[epp]+1;
        }
    }
    int a=0;
    while (a<epp) {
        cout << v[a] << " ";
        a++;
    }
    for (int i=uj; i<uj+m-epp; i++) {
        cout << i << " ";
    }
    cout << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base41/50
1Accepted0/03ms1812 KiB
2Accepted0/03ms2204 KiB
3Runtime error0/23ms2384 KiB
4Accepted2/23ms2432 KiB
5Accepted2/23ms2668 KiB
6Partially correct1/22ms2668 KiB
7Accepted2/23ms2720 KiB
8Runtime error0/23ms2824 KiB
9Accepted2/23ms2932 KiB
10Partially correct2/43ms3016 KiB
11Accepted4/43ms3048 KiB
12Accepted4/43ms3016 KiB
13Accepted4/43ms3144 KiB
14Partially correct2/44ms3364 KiB
15Accepted4/43ms3436 KiB
16Accepted6/63ms3468 KiB
17Accepted6/63ms3672 KiB