53802023-04-27 16:41:31TimiKövetkező permutáció (50 pont)cpp14Wrong answer 6/507ms4792 KiB
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    for (int i=0; i<n; i++)
        cin>>a[i];
    int i, j;
    if (a[n-1]>a[n-2])

        swap(a[n-1], a[n-2]);
    else
    {
        i=n-2;
        while(a[i]>a[i+1])
           i--;
        j=n-1;
        while (a[i]>a[j])
        {
            j--;
        }
        swap(a[i], a[j]);

        vector<int> utolsok;
        for(int k=i+1; k<n; k++)
            utolsok.push_back(a[k]);
        sort(utolsok.begin(), utolsok.end());
        int hatar;
        for (int k=0; k<utolsok.size(); k++)
        {
            if (a[k]>a[i])
            {
                hatar=k;
                break;
            }
        }
        j=1;
        for (int k=hatar-1; k>=0; k--)
        {
            a[i+j]=utolsok[k];
            j++;
        }
        for (int k=hatar; k<utolsok.size(); k++)
                a[i+k+1]=utolsok[k];
    }
    for (int k=0; k<n; k++)
        cout<<a[k]<<" ";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base6/50
1Accepted0/03ms1808 KiB
2Wrong answer0/04ms2092 KiB
3Wrong answer0/13ms2268 KiB
4Accepted1/13ms2484 KiB
5Accepted1/13ms2544 KiB
6Accepted1/13ms2772 KiB
7Wrong answer0/22ms3032 KiB
8Wrong answer0/23ms3196 KiB
9Wrong answer0/22ms3212 KiB
10Wrong answer0/22ms3232 KiB
11Wrong answer0/12ms3352 KiB
12Wrong answer0/12ms3476 KiB
13Wrong answer0/12ms3476 KiB
14Wrong answer0/13ms3696 KiB
15Wrong answer0/33ms3648 KiB
16Accepted3/33ms3840 KiB
17Wrong answer0/33ms4064 KiB
18Wrong answer0/33ms4120 KiB
19Wrong answer0/34ms4268 KiB
20Wrong answer0/36ms4352 KiB
21Wrong answer0/36ms4360 KiB
22Wrong answer0/37ms4360 KiB
23Wrong answer0/37ms4364 KiB
24Wrong answer0/37ms4360 KiB
25Wrong answer0/27ms4792 KiB
26Wrong answer0/27ms4648 KiB