53792023-04-27 16:40:42TimiKövetkező permutáció (50 pont)cpp14Wrong answer 0/5029ms4696 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]<<" "<<endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/03ms1816 KiB
2Wrong answer0/012ms2028 KiB
3Wrong answer0/13ms2132 KiB
4Wrong answer0/13ms2312 KiB
5Wrong answer0/13ms2528 KiB
6Wrong answer0/12ms2608 KiB
7Wrong answer0/23ms2736 KiB
8Wrong answer0/23ms2736 KiB
9Wrong answer0/23ms2896 KiB
10Wrong answer0/22ms2812 KiB
11Wrong answer0/13ms2968 KiB
12Wrong answer0/13ms2908 KiB
13Wrong answer0/13ms3292 KiB
14Wrong answer0/13ms3092 KiB
15Wrong answer0/33ms3224 KiB
16Wrong answer0/33ms3360 KiB
17Wrong answer0/34ms3584 KiB
18Wrong answer0/36ms3792 KiB
19Wrong answer0/317ms4016 KiB
20Wrong answer0/316ms4052 KiB
21Wrong answer0/317ms4284 KiB
22Wrong answer0/318ms4600 KiB
23Wrong answer0/324ms4456 KiB
24Wrong answer0/329ms4652 KiB
25Wrong answer0/225ms4696 KiB
26Wrong answer0/218ms4460 KiB