# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
405878 | 2021-05-17T02:13:47 Z | jk410 | Sorting (IOI15_sorting) | C++17 | 13 ms | 448 KB |
#include <bits/stdc++.h> #include "sorting.h" using namespace std; int A[200000],tmp_P[200000],tmp_Q[200000]; bool Visited[200000]; bool f(int N,int S[],int X[],int Y[],int k){ for (int i=0; i<N; i++) Visited[i]=false; for (int i=0; i<k; i++){ swap(S[X[i]],S[Y[i]]); tmp_P[i]=tmp_Q[i]=0; } int cnt=0; for (int i=0; i<N; i++){ if (S[i]!=i&&!Visited[i]){ Visited[i]=true; for (int j=S[i]; !Visited[j]; j=S[j]){ Visited[j]=true; tmp_P[cnt]=j; tmp_Q[cnt]=S[j]; cnt++; if (cnt>k) return false; } } } return true; } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { int ans; for (int i=0; i<N; i++) A[S[i]]=i; for (ans=0; ans<=N; ans++){ if (f(N,S,X,Y,ans)) break; } for (int i=0; i<ans; i++){ swap(A[S[X[i]]],A[S[Y[i]]]); swap(S[X[i]],S[Y[i]]); P[i]=A[tmp_P[i]]; Q[i]=A[tmp_Q[i]]; swap(S[A[tmp_P[i]]],S[A[tmp_Q[i]]]); swap(A[tmp_P[i]],A[tmp_Q[i]]); } return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 1 ms | 448 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Incorrect | 1 ms | 204 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 1 ms | 448 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Incorrect | 1 ms | 204 KB | Output isn't correct |
15 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 13 ms | 388 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 13 ms | 388 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |