# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
318144 | 2020-10-31T14:10:34 Z | tigicha | Sorting (IOI15_sorting) | C++14 | 2 ms | 492 KB |
#include <bits/stdc++.h> #include "sorting.h" using namespace std; int k, 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(a[a[v[i].first]], a[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 | 0 ms | 364 KB | Output is correct |
3 | Correct | 0 ms | 364 KB | Output is correct |
4 | Correct | 0 ms | 364 KB | Output is correct |
5 | Incorrect | 0 ms | 364 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 0 ms | 364 KB | Output is correct |
3 | Correct | 0 ms | 364 KB | Output is correct |
4 | Correct | 0 ms | 364 KB | Output is correct |
5 | Incorrect | 0 ms | 364 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Incorrect | 1 ms | 364 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 0 ms | 364 KB | Output is correct |
3 | Correct | 0 ms | 364 KB | Output is correct |
4 | Correct | 0 ms | 364 KB | Output is correct |
5 | Incorrect | 0 ms | 364 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 492 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 492 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |