# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
345666 | 2021-01-07T19:46:11 Z | ogibogi2004 | Sorting (IOI15_sorting) | C++14 | 2 ms | 748 KB |
#include "sorting.h" #include <bits/stdc++.h> using namespace std; const int MAXN=2e5+6; vector<pair<int,int> >swaps; int seq[MAXN],seq1[MAXN]; bool vis[MAXN]; int n; vector<pair<int,int> >moves; bool check(int x) { for(int i=0;i<n;i++) { seq1[i]=seq[i]; } for(int j=0;j<=x&&j<swaps.size();j++) { swap(seq1[swaps[j].first],seq1[swaps[j].second]); } int cnt=0; memset(vis,0,sizeof(vis)); moves.clear(); for(int i=0;i<n;i++) { if(vis[i]==0) { int u=i; while(vis[u]==0) { vis[u]=1; moves.push_back({i,seq1[u]}); u=seq1[u]; } cnt++; moves.pop_back(); } } //cout<<x<<" "<<cnt<<endl; if(n-cnt<=x+1)return 1; else return 0; } 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++)seq[i]=S[i]; for(int i=0;i<M;i++)swaps.push_back({X[i],Y[i]}); int low=0,high=n,mid,ans; while(low<=high) { mid=(low+high)/2; if(check(mid)) { ans=mid; high=mid-1; } else low=mid+1; } //cout<<ans<<endl; check(ans); for(int i=0;i<moves.size();i++) { P[i]=moves[i].first;Q[i]=moves[i].second; } return moves.size(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 492 KB | Output is correct |
2 | Correct | 1 ms | 492 KB | Output is correct |
3 | Correct | 1 ms | 492 KB | Output is correct |
4 | Correct | 1 ms | 492 KB | Output is correct |
5 | Correct | 1 ms | 492 KB | Output is correct |
6 | Correct | 1 ms | 492 KB | Output is correct |
7 | Correct | 1 ms | 492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 492 KB | Output is correct |
2 | Correct | 1 ms | 492 KB | Output is correct |
3 | Correct | 1 ms | 492 KB | Output is correct |
4 | Correct | 1 ms | 492 KB | Output is correct |
5 | Correct | 1 ms | 492 KB | Output is correct |
6 | Correct | 1 ms | 492 KB | Output is correct |
7 | Correct | 1 ms | 492 KB | Output is correct |
8 | Correct | 1 ms | 492 KB | Output is correct |
9 | Correct | 1 ms | 492 KB | Output is correct |
10 | Correct | 1 ms | 620 KB | Output is correct |
11 | Correct | 1 ms | 640 KB | Output is correct |
12 | Correct | 1 ms | 620 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 512 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 492 KB | Output is correct |
2 | Correct | 1 ms | 492 KB | Output is correct |
3 | Correct | 1 ms | 492 KB | Output is correct |
4 | Correct | 1 ms | 492 KB | Output is correct |
5 | Correct | 1 ms | 492 KB | Output is correct |
6 | Correct | 1 ms | 492 KB | Output is correct |
7 | Correct | 1 ms | 492 KB | Output is correct |
8 | Correct | 1 ms | 492 KB | Output is correct |
9 | Correct | 1 ms | 492 KB | Output is correct |
10 | Correct | 1 ms | 620 KB | Output is correct |
11 | Correct | 1 ms | 640 KB | Output is correct |
12 | Correct | 1 ms | 620 KB | Output is correct |
13 | Incorrect | 1 ms | 512 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 748 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 748 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |