# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
318154 | 2020-10-31T14:24:52 Z | tigicha | Sorting (IOI15_sorting) | C++14 | 386 ms | 21460 KB |
#include <bits/stdc++.h> #include "sorting.h" using namespace std; int l, r, ans, m, b[500005], a[500005]; vector<pair<int, int> > v; int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { l=0; r=M; ans=-1; while(l<=r){ m=(l+r)/2; for(int i=0; i<N; i++) b[i]=S[i]; for(int i=0; i<m; i++) swap(b[X[i]], b[Y[i]]); for(int i=0; i<N; i++) a[b[i]]=i; v.clear(); for(int i=0; i<N; i++){ if(b[i]==i) continue; v.push_back(make_pair(i, b[i])); swap(b[i], b[a[i]]); swap(a[i], a[b[a[i]]]); } if(v.size()>m) l=m+1; else{ for(int i=0; i<N; i++){ b[i]=S[i]; a[b[i]]=i; } for(int i=0; i<M; i++){ swap(a[b[X[i]]], a[b[Y[i]]]); swap(b[X[i]], b[Y[i]]); if(i<v.size()){ P[i]=a[v[i].first]; Q[i]=a[v[i].second]; swap(a[v[i].first], a[v[i].second]); swap(b[a[v[i].first]], b[a[v[i].second]]); } else{ P[i]=0; Q[i]=0; } } r=m-1; ans=m; } } return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 360 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 0 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 360 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 0 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 360 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 0 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 0 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 1 ms | 364 KB | Output is correct |
17 | Correct | 1 ms | 364 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
19 | Correct | 1 ms | 364 KB | Output is correct |
20 | Correct | 1 ms | 364 KB | Output is correct |
21 | Correct | 3 ms | 620 KB | Output is correct |
22 | Correct | 3 ms | 652 KB | Output is correct |
23 | Correct | 3 ms | 748 KB | Output is correct |
24 | Correct | 2 ms | 748 KB | Output is correct |
25 | Correct | 3 ms | 748 KB | Output is correct |
26 | Correct | 3 ms | 620 KB | Output is correct |
27 | Correct | 3 ms | 620 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 492 KB | Output is correct |
2 | Correct | 2 ms | 620 KB | Output is correct |
3 | Correct | 2 ms | 492 KB | Output is correct |
4 | Correct | 2 ms | 492 KB | Output is correct |
5 | Correct | 2 ms | 492 KB | Output is correct |
6 | Correct | 2 ms | 492 KB | Output is correct |
7 | Correct | 2 ms | 620 KB | Output is correct |
8 | Correct | 2 ms | 492 KB | Output is correct |
9 | Correct | 2 ms | 492 KB | Output is correct |
10 | Correct | 2 ms | 672 KB | Output is correct |
11 | Correct | 2 ms | 620 KB | Output is correct |
12 | Correct | 2 ms | 492 KB | Output is correct |
13 | Correct | 2 ms | 620 KB | Output is correct |
14 | Correct | 2 ms | 492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 492 KB | Output is correct |
2 | Correct | 2 ms | 620 KB | Output is correct |
3 | Correct | 2 ms | 492 KB | Output is correct |
4 | Correct | 2 ms | 492 KB | Output is correct |
5 | Correct | 2 ms | 492 KB | Output is correct |
6 | Correct | 2 ms | 492 KB | Output is correct |
7 | Correct | 2 ms | 620 KB | Output is correct |
8 | Correct | 2 ms | 492 KB | Output is correct |
9 | Correct | 2 ms | 492 KB | Output is correct |
10 | Correct | 2 ms | 672 KB | Output is correct |
11 | Correct | 2 ms | 620 KB | Output is correct |
12 | Correct | 2 ms | 492 KB | Output is correct |
13 | Correct | 2 ms | 620 KB | Output is correct |
14 | Correct | 2 ms | 492 KB | Output is correct |
15 | Correct | 219 ms | 19540 KB | Output is correct |
16 | Correct | 291 ms | 20052 KB | Output is correct |
17 | Correct | 316 ms | 20788 KB | Output is correct |
18 | Correct | 351 ms | 17752 KB | Output is correct |
19 | Correct | 275 ms | 19668 KB | Output is correct |
20 | Correct | 292 ms | 20180 KB | Output is correct |
21 | Correct | 258 ms | 20180 KB | Output is correct |
22 | Correct | 214 ms | 19412 KB | Output is correct |
23 | Correct | 250 ms | 21332 KB | Output is correct |
24 | Correct | 349 ms | 21076 KB | Output is correct |
25 | Correct | 386 ms | 20944 KB | Output is correct |
26 | Correct | 308 ms | 19692 KB | Output is correct |
27 | Correct | 302 ms | 19032 KB | Output is correct |
28 | Correct | 304 ms | 20820 KB | Output is correct |
29 | Correct | 351 ms | 20568 KB | Output is correct |
30 | Correct | 279 ms | 18268 KB | Output is correct |
31 | Correct | 379 ms | 20692 KB | Output is correct |
32 | Correct | 248 ms | 20820 KB | Output is correct |
33 | Correct | 366 ms | 21076 KB | Output is correct |
34 | Correct | 277 ms | 21076 KB | Output is correct |
35 | Correct | 270 ms | 19668 KB | Output is correct |
36 | Correct | 167 ms | 17252 KB | Output is correct |
37 | Correct | 352 ms | 21460 KB | Output is correct |
38 | Correct | 341 ms | 20820 KB | Output is correct |
39 | Correct | 343 ms | 20948 KB | Output is correct |