53782023-04-27 16:34:38TimiKövetkező permutáció (50 pont)cpp11Wrong answer 6/507ms4484 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/03ms1848 KiB
2Wrong answer0/04ms2112 KiB
3Wrong answer0/13ms2460 KiB
4Accepted1/13ms2524 KiB
5Accepted1/13ms2480 KiB
6Accepted1/13ms2672 KiB
7Wrong answer0/23ms2748 KiB
8Wrong answer0/23ms3116 KiB
9Wrong answer0/23ms3132 KiB
10Wrong answer0/23ms3220 KiB
11Wrong answer0/13ms3424 KiB
12Wrong answer0/13ms3532 KiB
13Wrong answer0/13ms3748 KiB
14Wrong answer0/13ms3872 KiB
15Wrong answer0/33ms3888 KiB
16Accepted3/33ms4004 KiB
17Wrong answer0/33ms3888 KiB
18Wrong answer0/33ms4016 KiB
19Wrong answer0/34ms3984 KiB
20Wrong answer0/36ms3984 KiB
21Wrong answer0/36ms4328 KiB
22Wrong answer0/36ms4384 KiB
23Wrong answer0/37ms4376 KiB
24Wrong answer0/36ms4296 KiB
25Wrong answer0/27ms4484 KiB
26Wrong answer0/27ms4180 KiB