# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
794910 | Username4132 | Sorting (IOI15_sorting) | C++14 | 27 ms | 3412 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "sorting.h"
#include<iostream>
#include<algorithm>
using namespace std;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
const int MAXN = 610;
int n, cou, ans, arr[MAXN][MAXN];
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
n=N;
forn(i, n) arr[0][i]=S[i];
forn(i, n-1){
forn(j, n) arr[i+1][j]=arr[i][j];
swap(arr[i+1][X[i]], arr[i+1][Y[i]]);
}
forn(i, n-1){
int num = arr[n-1][i];
forsn(j, i+1, n){
int x = find(arr[j], arr[j]+n, num) - arr[j];
int y = find(arr[j], arr[j]+n, i) - arr[j];
swap(arr[j][x], arr[j][y]);
if(j==i+1) P[cou]=x, Q[cou]=y, ++cou;
}
}
while(true){
bool flag=true;
forn(i, n) flag&=(S[i]==i);
if(flag) break;
swap(S[X[ans]], S[Y[ans]]);
swap(S[P[ans]], S[Q[ans]]);
++ans;
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |