# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
314638 | 2020-10-20T14:00:20 Z | amunduzbaev | Sorting (IOI15_sorting) | C++14 | 2 ms | 768 KB |
//#include "grader.cpp" #include "sorting.h" #include <bits/stdc++.h> using namespace std; #define pb(a) push_back(a) const int N=2*1e5+5; int n, s[N], x[N], y[N]; vector<pair<int,int>>ans; bool check(int m){ int a[N], pos[N]; for(int i=0;i<n;i++) a[i]=s[i]; for(int i=0;i<m;i++) swap(a[x[i]], a[y[i]]); for(int i=0;i<n;i++) pos[a[i]]=i; vector<int> sx, sy; for(int i=0;i<n;i++){ if(pos[i]!=i){ int j=pos[i]; sx.pb(a[i]); sy.pb(a[j]); pos[a[i]]=j; swap(a[i],a[j]); } } if(sx.size()>m) return false; ans.clear(); for(int i=0;i<n;i++) a[i]=s[i], pos[a[i]]=i; for(int i=0;i<sx.size();i++){ int x1=x[i], y1=y[i], i1=sx[i], j1=sy[i]; ans[i] = {pos[i1],pos[j1]}; i1=pos[i1],j1=pos[j1]; swap ( a[x1] ,a[y1] ); swap ( a[i1], a[j1] ); swap ( pos[a[x1]], pos[a[y1]] ); swap ( pos[a[i1]], pos[a[j1]] ); } for(int i=sx.size(); i<m; i++) ans.push_back({0,0}); return true; } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n=N; for(int i=0;i<n;i++) s[i]=S[i]; for(int i=0;i<M;i++) x[i]=X[i], y[i]=Y[i]; int l=0,r=M; while(l<r){ int md=(l+r)/2; if(check(md)) r=md; else l=md+1; } for(int i=0;i<ans.size();i++){ P[i]=ans[i].first; Q[i]=ans[i].second; } return l; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Runtime error | 1 ms | 512 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Runtime error | 1 ms | 512 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Runtime error | 1 ms | 512 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Runtime error | 1 ms | 512 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 768 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 768 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |