50562023-04-13 10:07:32czitaKövetkező permutáció (50 pont)cpp17Runtime error 3/507ms4340 KiB
// permutacio.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> X(n, 0);
    for (size_t i = 0; i < n; i++)
    {
        cin >> X[i];
    }
    vector<int> Y;
    int db = n - 2;
    Y.push_back(X[n - 1]);
    while ((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.capacity()-1;
    while (maxy>0&&Y[maxy-1]>ut)
    {
        maxy--;
    }
    
    X[db - 1] = Y[maxy];
    for (int i = maxy-1; i >=0; i--)
    {
        X[db] = Y[i];
        db++;
    }
    for (int i = Y.capacity()-1; i > maxy; i--)
    {
        X[db] = Y[i];
        db++;
    }
    for (auto a : X)
    {
        cout << a<<" ";
    }
    cout << endl;
   
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base3/50
1Accepted0/03ms1840 KiB
2Runtime error0/04ms2104 KiB
3Wrong answer0/13ms2204 KiB
4Wrong answer0/13ms2440 KiB
5Wrong answer0/12ms2496 KiB
6Accepted1/12ms2600 KiB
7Wrong answer0/23ms2848 KiB
8Wrong answer0/23ms2984 KiB
9Wrong answer0/23ms3204 KiB
10Wrong answer0/23ms3172 KiB
11Wrong answer0/12ms3168 KiB
12Wrong answer0/13ms3292 KiB
13Wrong answer0/12ms3380 KiB
14Wrong answer0/13ms3380 KiB
15Wrong answer0/33ms3508 KiB
16Wrong answer0/33ms3596 KiB
17Runtime error0/33ms3828 KiB
18Runtime error0/34ms3904 KiB
19Runtime error0/36ms4044 KiB
20Runtime error0/36ms4072 KiB
21Runtime error0/36ms4148 KiB
22Runtime error0/37ms4040 KiB
23Runtime error0/37ms4180 KiB
24Runtime error0/37ms4136 KiB
25Runtime error0/26ms4340 KiB
26Accepted2/27ms4004 KiB