Submission #590866

#TimeUsernameProblemLanguageResultExecution timeMemory
590866FatihSolakSorting (IOI15_sorting)C++17
54 / 100
4 ms596 KiB
#include "sorting.h" #include <bits/stdc++.h> using namespace std; int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) { if(is_sorted(s,s+n)) return 0; for(int i = 0;i<m;i++){ p[i] = q[i] = 0; } vector<int> fnal; vector<int> now; vector<int> pfnal(n,0); vector<int> pnow(n,0); int cnt = 0; for(int i = 0;i<n;i++){ fnal.push_back(s[i]); pfnal[s[i]] = i; now.push_back(s[i]); pnow[s[i]] = i; cnt += (s[i] == i); } for(int i = 0;i<m;i++){ swap(pfnal[fnal[x[i]]],pfnal[fnal[y[i]]]); swap(fnal[x[i]],fnal[y[i]]); } for(int i = 0;i<m;i++){ swap(pnow[now[x[i]]],pnow[now[y[i]]]); swap(now[x[i]],now[y[i]]); if(i < n){ int ps1 = pnow[i]; int ps2 = pnow[fnal[i]]; p[i] = ps1; q[i] = ps2; swap(pnow[now[ps1]],pnow[now[ps2]]); swap(now[ps1],now[ps2]); int tmp = pfnal[i]; swap(pfnal[fnal[i]],pfnal[i]); swap(fnal[i],fnal[tmp]); } if(is_sorted(now.begin(),now.end())) return i+1; } assert(0); }
#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...