Submission #1122105

#TimeUsernameProblemLanguageResultExecution timeMemory
1122105SalihSahinSorting (IOI15_sorting)C++14
20 / 100
56 ms504 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; #include "sorting.h" int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]){ bool sorted = 1; for(int i = 0; i < N; i++){ if(S[i] != i) sorted = 0; } if(sorted) return 0; int ans = 0; for(int i = 0; i < M; i++){ ans++; swap(S[X[i]], S[Y[i]]); sorted = 1; for(int j = 0; j < N; j++){ if(S[j] != j) sorted = 0; } if(sorted){ P[i] = Q[i] = 0; return ans; } int ind1 = 0; for(int j = 0; j < N; j++){ if(S[j] != j){ ind1 = j; break; } } vector<int> perm(N); for(int j = 0; j < N; j++){ perm[j] = j; } random_shuffle(perm.begin(), perm.end()); int ind2 = 0; for(int j = 0; j < N; j++){ if(perm[j] == ind1) continue; if(S[perm[j]] != perm[j] && S[ind1] == perm[j]){ ind2 = perm[j]; break; } } swap(S[ind1], S[ind2]); P[i] = ind1; Q[i] = ind2; sorted = 1; for(int j = 0; j < N; j++){ if(S[j] != j) sorted = 0; } if(sorted){ return ans; } } return -1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...