9982022-02-20 07:57:38Szin AttilaKombináció (50)cpp14Time limit exceeded 2/50298ms1876 KiB
#include <bits/stdc++.h>
using namespace std;
#define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using ll = long long;

const int maxN = 2e5 + 5;
const int MOD = 1e9 + 7;

string s, curr;
int n,m;

bool kisebb(string a) {
    for(int i = 0; i < m-1; i++) {
        if(a[i] > a[i+1]) return false;
    }

    return s.substr(0, m) > a.substr(0, m);
}

bool nagyobb(string a) {
    for(int i = 0; i < m-1; i++) {
        if(a[i] > a[i+1]) return false;
    }
    
    return s.substr(0, m) < a.substr(0, m);
}

int main() {



   InTheNameOfGod;
    
    
    cin >> n >> m;

    vector<bool> volt(n+1, 0);

    
    for(int i = 0; i < m; i++) {
        int x;
        cin >> x;
        volt[x] = 1;

        s.push_back('0' + x);
    }

    curr = s;
    for(int i = n; i > 0; i--) if(!volt[i]) curr.push_back('0' + i);

    while(!kisebb(curr)) prev_permutation(curr.begin(), curr.end());
    for(int i = 0; i < m; i++) cout << curr[i] << ' ';
    cout << "\n";
    curr = s;

    for(int i = 1; i <= n; i++) if(!volt[i]) curr.push_back('0' + i);

    while(!nagyobb(curr)) next_permutation(curr.begin(), curr.end());

    for(int i = 0; i < m; i++) cout << curr[i] << ' ';

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base2/50
1Accepted0/02ms1812 KiB
2Time limit exceeded0/0296ms940 KiB
3Time limit exceeded0/2286ms1000 KiB
4Accepted2/230ms1860 KiB
5Time limit exceeded0/2298ms936 KiB
6Time limit exceeded0/2245ms1008 KiB
7Wrong answer0/21ms1876 KiB
8Time limit exceeded0/2298ms1080 KiB
9Time limit exceeded0/2298ms1020 KiB
10Time limit exceeded0/4298ms1084 KiB
11Time limit exceeded0/4266ms1152 KiB
12Time limit exceeded0/4231ms964 KiB
13Time limit exceeded0/4203ms1036 KiB
14Time limit exceeded0/4202ms1104 KiB
15Time limit exceeded0/4241ms1108 KiB
16Time limit exceeded0/6248ms980 KiB
17Time limit exceeded0/6203ms1048 KiB