# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
421247 | 2021-06-08T22:50:19 Z | Pbezz | Sorting (IOI15_sorting) | C++14 | 4 ms | 332 KB |
#include "sorting.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back typedef pair<ll,ll> pii; const ll MAXN=2e5+5; const ll INF=1e9+7; int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { int i,k,j,R=0; bool ok=true; for(i=0;i<N;i++){ if(S[i]!=i)ok=false; } if(ok)return 0; if(Y[0]==1){//cout<<"haha1"; swap(S[0],S[1]); bool f=false; if(S[0]==0&&S[1]!=1){ for(k=0;k<N;k++){ if(S[k]==1)break; } P[0]=k; Q[0]=1; R++; swap(S[k],S[1]); ok=true; for(j=0;j<N;j++){ if(S[j]!=j)ok=false; } if(ok){ return R; } swap(S[0],S[1]); }else if(S[0]!=0&&S[1]==1){ for(k=0;k<N;k++){ if(S[k]==0)break; } P[0]=k; Q[0]=0; R++; swap(S[k],S[0]); ok=true; for(j=0;j<N;j++){ if(S[j]!=j)ok=false; } if(ok){ return R; } swap(S[0],S[1]); }else if(S[0]!=0&&S[1]!=1){f=true; for(k=0;k<N;k++){ if(S[k]==0)break; } P[0]=k; Q[0]=1; R++; swap(S[k],S[1]); ok=true; for(j=0;j<N;j++){ if(S[j]!=j)ok=false; } if(ok){ return R; } swap(S[0],S[1]); //0 in place if(S[1]!=1){f=true; for(k=0;k<N;k++){ if(S[k]==1)break; } P[R]=k; Q[R]=1; R++; swap(S[k],S[1]); ok=true; for(j=0;j<N;j++){ if(S[j]!=j)ok=false; } if(ok){ return R; } swap(S[0],S[1]); } } for(i=2;i<N;i++){//find i, send it to ith position for(k=0;k<N;k++){ if(S[k]==i)break; } if(k!=i){ P[R]=k; Q[R]=i; R++; swap(S[k],S[i]); ok=true; for(j=0;j<N;j++){ if(S[j]!=j)ok=false; } if(ok){ return R; } } } if(f&&R%2==1){ P[R]=0; Q[R]=0; R++; }else if(f==false && R%2==0 ){ P[R]=0; Q[R]=0; R++; } }else{//his moves are redundant for(i=0;i<N;i++){//find i, send it to ith position for(k=0;k<N;k++){ if(S[k]==i)break; } if(k!=i){ P[R]=k; Q[R]=i; R++; swap(S[k],S[i]); ok=true; for(j=0;j<N;j++){ if(S[j]!=j)ok=false; } if(ok){ return R; } } } /* for(i=0;i<N;i++){ cout<<S[i]<<" "; }cout<<endl;*/ //while(R>0&&P[R-1]==Q[R-1])R--; } return R; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 1 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Incorrect | 0 ms | 204 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 1 ms | 204 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Incorrect | 0 ms | 204 KB | Output isn't correct |
15 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 332 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 332 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |