# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
298521 | 2020-09-13T04:14:40 Z | TMJN | Sorting (IOI15_sorting) | C++17 | 172 ms | 20548 KB |
#include "sorting.h" #include <bits/stdc++.h> using namespace std; int s[200000]; int k[200000]; int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { bool f=true; for(int i=0;i<N;i++){ if(S[i]!=i)f=false; } if(f)return 0; int l,r; l=-1; r=M; while(l+1!=r){ int m=(l+r)/2; for(int i=0;i<N;i++){ s[i]=S[i]; } for(int i=0;i<=m;i++){ swap(s[X[i]],s[Y[i]]); } for(int i=0;i<N;i++){ k[s[i]]=i; } int c=0; for(int i=0;i<N;i++){ if(s[i]!=i){ c++; swap(s[i],s[k[i]]); swap(k[i],k[s[k[i]]]); } } if(c<=m+1){ r=m; } else{ l=m; } } for(int i=0;i<N;i++){ s[i]=S[i]; } for(int i=0;i<=r;i++){ swap(s[X[i]],s[Y[i]]); } for(int i=0;i<N;i++){ k[s[i]]=i; } vector<pair<int,int>>vp; for(int i=0;i<N;i++){ if(s[i]!=i){ vp.push_back({s[i],s[k[i]]}); swap(s[i],s[k[i]]); swap(k[s[i]],k[s[k[i]]]); } } if(vp.size()!=r+1){ vp.push_back({0,0}); } for(int i=0;i<N;i++){ s[i]=S[i]; } for(int i=0;i<N;i++){ k[s[i]]=i; } for(int i=0;i<=r;i++){ swap(s[X[i]],s[Y[i]]); swap(k[s[X[i]]],k[s[Y[i]]]); P[i]=k[vp[i].first]; Q[i]=k[vp[i].second]; swap(s[P[i]],s[Q[i]]); swap(k[s[P[i]]],k[s[Q[i]]]); } return r+1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 512 KB | Output is correct |
9 | Correct | 1 ms | 256 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 384 KB | Output is correct |
12 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 512 KB | Output is correct |
9 | Correct | 1 ms | 256 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 384 KB | Output is correct |
12 | Correct | 1 ms | 384 KB | Output is correct |
13 | Correct | 1 ms | 384 KB | Output is correct |
14 | Correct | 1 ms | 384 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
16 | Correct | 1 ms | 384 KB | Output is correct |
17 | Correct | 1 ms | 384 KB | Output is correct |
18 | Correct | 1 ms | 384 KB | Output is correct |
19 | Correct | 1 ms | 256 KB | Output is correct |
20 | Correct | 1 ms | 384 KB | Output is correct |
21 | Correct | 2 ms | 512 KB | Output is correct |
22 | Correct | 1 ms | 512 KB | Output is correct |
23 | Correct | 1 ms | 640 KB | Output is correct |
24 | Correct | 1 ms | 512 KB | Output is correct |
25 | Correct | 1 ms | 512 KB | Output is correct |
26 | Correct | 1 ms | 512 KB | Output is correct |
27 | Correct | 1 ms | 512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 512 KB | Output is correct |
2 | Correct | 2 ms | 512 KB | Output is correct |
3 | Correct | 2 ms | 512 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 512 KB | Output is correct |
6 | Correct | 2 ms | 512 KB | Output is correct |
7 | Correct | 2 ms | 512 KB | Output is correct |
8 | Correct | 2 ms | 512 KB | Output is correct |
9 | Correct | 2 ms | 512 KB | Output is correct |
10 | Correct | 2 ms | 512 KB | Output is correct |
11 | Correct | 2 ms | 512 KB | Output is correct |
12 | Correct | 2 ms | 512 KB | Output is correct |
13 | Correct | 2 ms | 544 KB | Output is correct |
14 | Correct | 1 ms | 512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 512 KB | Output is correct |
2 | Correct | 2 ms | 512 KB | Output is correct |
3 | Correct | 2 ms | 512 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 512 KB | Output is correct |
6 | Correct | 2 ms | 512 KB | Output is correct |
7 | Correct | 2 ms | 512 KB | Output is correct |
8 | Correct | 2 ms | 512 KB | Output is correct |
9 | Correct | 2 ms | 512 KB | Output is correct |
10 | Correct | 2 ms | 512 KB | Output is correct |
11 | Correct | 2 ms | 512 KB | Output is correct |
12 | Correct | 2 ms | 512 KB | Output is correct |
13 | Correct | 2 ms | 544 KB | Output is correct |
14 | Correct | 1 ms | 512 KB | Output is correct |
15 | Correct | 136 ms | 18040 KB | Output is correct |
16 | Correct | 152 ms | 18524 KB | Output is correct |
17 | Correct | 168 ms | 19472 KB | Output is correct |
18 | Correct | 45 ms | 13432 KB | Output is correct |
19 | Correct | 135 ms | 17836 KB | Output is correct |
20 | Correct | 145 ms | 18388 KB | Output is correct |
21 | Correct | 141 ms | 18496 KB | Output is correct |
22 | Correct | 127 ms | 14840 KB | Output is correct |
23 | Correct | 150 ms | 20316 KB | Output is correct |
24 | Correct | 167 ms | 19956 KB | Output is correct |
25 | Correct | 172 ms | 19716 KB | Output is correct |
26 | Correct | 139 ms | 18392 KB | Output is correct |
27 | Correct | 132 ms | 17752 KB | Output is correct |
28 | Correct | 162 ms | 19792 KB | Output is correct |
29 | Correct | 157 ms | 19152 KB | Output is correct |
30 | Correct | 104 ms | 17160 KB | Output is correct |
31 | Correct | 162 ms | 19768 KB | Output is correct |
32 | Correct | 151 ms | 19552 KB | Output is correct |
33 | Correct | 172 ms | 19972 KB | Output is correct |
34 | Correct | 158 ms | 19832 KB | Output is correct |
35 | Correct | 134 ms | 17672 KB | Output is correct |
36 | Correct | 68 ms | 15992 KB | Output is correct |
37 | Correct | 172 ms | 20548 KB | Output is correct |
38 | Correct | 170 ms | 19716 KB | Output is correct |
39 | Correct | 164 ms | 19832 KB | Output is correct |