51352023-04-19 21:38:51TimiKövetkező permutáció (50 pont)cpp11Time limit exceeded 12/50347ms4536 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
void kovetkezo(vector<int>& a, int n)
{
   int i, j;
    i=n-2;
    while ((i>=0)&&(a[i]>a[i+1]))
        i--;

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

bool vanbenne(vector<int>& a, int n)
{
    int i, j, k;
    for (i=0; i<n-2; i++)
        for (j=i+1; j<n-1; j++)
           for (k=j+1; k<n; k++)
              if (a[i]>a[j] && a[i]>a[k] && a[j]<a[k])
                 return true;
    return false;
}
int main()
{
    int n, i;
    cin>>n;
    vector<int> a(n);
    for (i=0; i<n; i++)
        cin>>a[i];
    kovetkezo(a, n);
    while (vanbenne(a, n))
        kovetkezo(a, n);
    for (i=0; i<n; i++)
        cout<<a[i]<<" ";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base12/50
1Accepted0/03ms1812 KiB
2Time limit exceeded0/0300ms1264 KiB
3Accepted1/12ms2284 KiB
4Accepted1/12ms2428 KiB
5Accepted1/13ms2672 KiB
6Accepted1/13ms2920 KiB
7Accepted2/23ms3000 KiB
8Accepted2/28ms3096 KiB
9Accepted2/23ms3308 KiB
10Accepted2/22ms3488 KiB
11Time limit exceeded0/1256ms3548 KiB
12Time limit exceeded0/1270ms3664 KiB
13Time limit exceeded0/1275ms3664 KiB
14Time limit exceeded0/1266ms3668 KiB
15Time limit exceeded0/3256ms3792 KiB
16Time limit exceeded0/3287ms3552 KiB
17Time limit exceeded0/3252ms3680 KiB
18Time limit exceeded0/3263ms3768 KiB
19Time limit exceeded0/3275ms3792 KiB
20Time limit exceeded0/3252ms3792 KiB
21Time limit exceeded0/3268ms4024 KiB
22Time limit exceeded0/3347ms3444 KiB
23Time limit exceeded0/3268ms4364 KiB
24Time limit exceeded0/3298ms4372 KiB
25Time limit exceeded0/2256ms4456 KiB
26Time limit exceeded0/2259ms4536 KiB