50572023-04-13 11:34:08czitaKövetkező permutáció (50 pont)cpp11Runtime error 3/507ms4564 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 (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.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/03ms1688 KiB
2Runtime error0/04ms2056 KiB
3Wrong answer0/13ms2060 KiB
4Wrong answer0/13ms2268 KiB
5Wrong answer0/13ms2484 KiB
6Accepted1/13ms2700 KiB
7Wrong answer0/22ms2812 KiB
8Wrong answer0/22ms2804 KiB
9Wrong answer0/22ms3056 KiB
10Wrong answer0/23ms3148 KiB
11Wrong answer0/13ms3388 KiB
12Wrong answer0/13ms3728 KiB
13Wrong answer0/12ms3656 KiB
14Wrong answer0/13ms3752 KiB
15Wrong answer0/33ms3756 KiB
16Wrong answer0/33ms3996 KiB
17Runtime error0/33ms4228 KiB
18Runtime error0/33ms4232 KiB
19Runtime error0/34ms4328 KiB
20Runtime error0/36ms4104 KiB
21Runtime error0/36ms4384 KiB
22Runtime error0/37ms4456 KiB
23Runtime error0/37ms4448 KiB
24Runtime error0/37ms4496 KiB
25Runtime error0/26ms4564 KiB
26Accepted2/27ms4440 KiB