8652022-01-21 20:03:27Valaki2Kombináció (50)cpp14Elfogadva 50/502ms1984 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int n, m;
vector<bool> is;
vector<bool> ans;

void solve() {
    cin >> n >> m;
    is.assign(1 + n, false);
    for(int i = 0; i < m; i++) {
        int x;
        cin >> x;
        is[x] = true;
    }
    ans.assign(1 + n, false);
    bool ok = false;
    for(int i = 1; i <= m; i++) {
        if(!is[i]) {
            ok = true;
        }
    }
    if(!ok) {
        for(int i = n; i >= n - m + 1; i--) {
            ans[i] = true;
        }
    } else {
        int pos = 0;
        for(int i = n; i >= 1; i--) {
            if(is[i] && !is[i - 1]) {
                ans = is;
                ans[i] = false;
                ans[i - 1] = true;
                pos = i;
                break;
            }
        }
        int cnt = 0;
        for(int i = pos; i <= n; i++) {
            if(ans[i]) {
                cnt++;
            }
            ans[i] = 0;
        }
        for(int i = n; i >= n - cnt + 1; i--) {
            ans[i] = 1;
        }
    }
    for(int i = 1; i <= n; i++) {
        if(ans[i]) {
            cout << i << " ";
        }
    }
    cout << "\n";
    ans.assign(1 + n, false);
    ok = false;
    for(int i = n; i >= n - m + 1; i--) {
        if(!is[i]) {
            ok = true;
        }
    }
    if(!ok) {
        for(int i = 1; i <= m; i++) {
            ans[i] = true;
        }
    } else {
        int pos = 0;
        for(int i = n; i >= 1; i--) {
            if(!is[i] && is[i - 1]) {
                ans = is;
                ans[i] = true;
                ans[i - 1] = false;
                pos = i + 1;
                break;
            }
        }
        int cnt = 0;
        for(int i = pos; i <= n; i++) {
            if(ans[i]) {
                cnt++;
            }
            ans[i] = 0;
        }
        for(int i = pos; i <= pos + cnt - 1; i++) {
            ans[i] = 1;
        }
    }
    for(int i = 1; i <= n; i++) {
        if(ans[i]) {
            cout << i << " ";
        }
    }
    cout << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/02ms1816 KiB
2Elfogadva0/01ms1860 KiB
3Elfogadva2/21ms1920 KiB
4Elfogadva2/21ms1924 KiB
5Elfogadva2/21ms1932 KiB
6Elfogadva2/21ms1936 KiB
7Elfogadva2/21ms1936 KiB
8Elfogadva2/21ms1948 KiB
9Elfogadva2/21ms1944 KiB
10Elfogadva4/41ms1952 KiB
11Elfogadva4/41ms1956 KiB
12Elfogadva4/41ms1964 KiB
13Elfogadva4/41ms1960 KiB
14Elfogadva4/41ms1968 KiB
15Elfogadva4/41ms1972 KiB
16Elfogadva6/61ms1976 KiB
17Elfogadva6/61ms1984 KiB