# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
761967 | 2023-06-20T13:03:38 Z | Ahmed57 | Sorting (IOI15_sorting) | C++17 | 1 ms | 340 KB |
#include <bits/stdc++.h> using namespace std; int lol[100001],vis[100001]; vector<int> v; void dfs(int i){ vis[i] = 1; v.push_back(i); if(vis[lol[i]]==0)dfs(lol[i]); } //int P[100001] , Q[100001]; int findSwapPairs(int N,int S[],int M,int X[],int Y[],int P[],int Q[]){ if(N==1)return 0; int ans = 0; swap(S[0],S[1]); int on = 0 , ze = 0; for(int i = 0;i<N;i++){ if(S[i]==0)ze = i; if(S[i]==1)on = i; } if(ze>1){ swap(S[(on?0:1)],S[ze]); P[0] = ze , Q[0] = (on?0:1); //cout<<ze<<"hh"<<endl; ans++; swap(S[0],S[1]); if(on>1){ swap(S[0],S[on]); P[1] = 0 , Q[1] = on; ans++; swap(S[0],S[1]); } }else if(on>1){ if(ze==0){ P[0] = on; Q[0] = 1; ans++; }else{ P[0] = on; Q[0] = 0; ans++; } swap(S[0],S[1]); } for(int i = 0;i<N;i++){ lol[i] = S[i]; vis[i] = 0; } int ha = -1; for(int i = 2;i<N;i++){ if(vis[i]==0){ v.clear(); dfs(i); for(int j = 1;j<v.size();j++){ ha++; P[ans] = v[0]; Q[ans] = v[j]; ans++; } } } if(ha==-1){ if(S[0]==1){ return ans; }else{ P[ans] = 0; Q[ans] = 0; ans++; return ans; } }else{ int pr = ha%2; if(S[pr]==0){ return ans; }else{ P[ans] = 0; Q[ans] = 0; ans++; return ans; } } } /* int main(){ int S[] = {2,3,0,1,4}; 3 2 0 1 4 E 0 2 3 1 4 A 2 0 3 1 4 E 1 0 3 2 4 A 0 1 3 2 4 E 0 1 2 3 4 A int X[] = {0,0,0,0,0,0,0,0,0,0,0}; int Y[] = {1,1,1,1,1,1,1,1,1,1,1}; cout<<findSwapPairs(5,S,100,X,Y)<<endl; for(int i = 0;i<10;i++){ cout<<P[i]<<" "<<Q[i]<<endl; } }*/
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 0 ms | 256 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 0 ms | 256 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 0 ms | 212 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 0 ms | 256 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |