50662023-04-13 17:34:33czitaKövetkező permutáció (50 pont)cpp11Accepted 50/507ms4388 KiB
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n = 6000;
    cin >> n;
    vector<int> X(n, 0);

    for (size_t i = 0; i < n; i++)
    {
        cin >> X[i];
    }
    vector<int> Y;
    int db = n - 1;
    // Y.push_back(X[n - 1]);
    while (db > 0 && (X[db] <= X[db - 1]))
    {
        Y.push_back(X[db]);
        db--;
    }
    int ut = X[db - 1];
    Y.push_back(X[db]);
    Y.push_back(X[db - 1]);
    sort(Y.begin(), Y.end());
    int maxy = Y.size() - 1;
    while (Y[maxy - 1] > ut)
    {
        maxy--;
    }
    X[db - 1] = Y[maxy];
    for (int i = maxy - 1; i >= 0; i--)//berakja a kisebb elemeket
    {

        X[db] = Y[i];
        db++;

    }
    int maxx = Y.size() - 1;
    for (int i =maxy+1; i < Y.size(); i++)
    {

        X[db] = Y[i];
        db++;

    }
    for (auto a : X)
    {
        cout << a << " ";
    }
    cout << endl;

}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1812 KiB
2Accepted0/04ms2024 KiB
3Accepted1/12ms2216 KiB
4Accepted1/12ms2432 KiB
5Accepted1/13ms2636 KiB
6Accepted1/13ms2852 KiB
7Accepted2/23ms3092 KiB
8Accepted2/23ms3428 KiB
9Accepted2/23ms3636 KiB
10Accepted2/22ms3560 KiB
11Accepted1/13ms3684 KiB
12Accepted1/12ms3764 KiB
13Accepted1/13ms3728 KiB
14Accepted1/13ms3976 KiB
15Accepted3/33ms4096 KiB
16Accepted3/33ms3980 KiB
17Accepted3/33ms3952 KiB
18Accepted3/33ms3956 KiB
19Accepted3/34ms3976 KiB
20Accepted3/36ms4056 KiB
21Accepted3/36ms4064 KiB
22Accepted3/36ms4148 KiB
23Accepted3/36ms4224 KiB
24Accepted3/36ms4212 KiB
25Accepted2/27ms4364 KiB
26Accepted2/27ms4388 KiB