235562026-01-24 18:17:23miszorimarciKombináció (50)cpp17Hibás válasz 46/501ms508 KiB
// Do it recursively

#include <bits/stdc++.h>
using namespace std;

int N, M;
vector<int>a;

bool prev(int x)
{
    if(x != N-1)
    {
        if(prev(x+1))return 1;
    }
    if(x != 0 && a[x]-1 != a[x-1])
    {
        for(int j = 0; j < x; j++)cout << a[j] << " ";
        cout << a[x]-1 << " ";
        for(int j = x+1; j < N; j++)cout << a[j] << " ";
        return 1;
    }
    if(x == 0 && a[x] != 1)
    {
        cout << a[0]-1 << " ";
        for(int j = 1; j < N; j++)cout << a[j] << " ";
        return 1;
    }
    return 0;
    
}

bool nxt(int x)
{
    if(x != N-1)
    {
        if(nxt(x+1))return 1;
    }
    if(x != N-1 && a[x]+1 != a[x+1])
    {
        for(int j = 0; j < x; j++)cout << a[j] << " ";
        cout << a[x]+1 << " ";
        for(int j = x+1; j < N; j++)cout << a[j] << " ";
        return 1;
    }
    if(x == N-1 && a[x] != M)
    {
        for(int j = 0; j < N-1; j++)cout << a[j] << " ";
        cout << a[x]+1 << " ";
        return 1;
    }
    return 0;
}

int main() {
	cin >> M >> N;
    a.resize(N);
    for(int &i : a)cin >> i;
    if(!prev(0))
    {
        for(int i = 0; i < N; i++)
        {
            cout << M-(N-i)+1 << " ";
        }
    }
    cout << "\n";
    if(!nxt(0))
    {
        for(int i = 0; i < N; i++)
        {
            cout << i+1 << " ";
        }
    }
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base46/50
1Elfogadva0/01ms508 KiB
2Hibás válasz0/01ms500 KiB
3Elfogadva2/21ms508 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva2/21ms316 KiB
6Elfogadva2/21ms316 KiB
7Részben helyes1/21ms316 KiB
8Elfogadva2/21ms316 KiB
9Elfogadva2/21ms316 KiB
10Elfogadva4/41ms316 KiB
11Elfogadva4/41ms316 KiB
12Elfogadva4/41ms316 KiB
13Elfogadva4/41ms316 KiB
14Elfogadva4/41ms508 KiB
15Elfogadva4/41ms316 KiB
16Elfogadva6/61ms316 KiB
17Részben helyes3/61ms316 KiB