Submission #196873

#TimeUsernameProblemLanguageResultExecution timeMemory
196873jovan_bSorting (IOI15_sorting)C++17
100 / 100
810 ms32080 KiB
#include "sorting.h" #include <bits/stdc++.h> using namespace std; int niz[200005]; int x[600005], y[600005]; int p[600005], q[600005]; int n, m; int prvo[200005]; int gde[200005]; int who[200005]; int tren[200005]; int trenwho[200005]; bool check(int k){ for(int i=0; i<n; i++){ gde[niz[i]] = i; who[i] = niz[i]; tren[niz[i]] = i; trenwho[i] = niz[i]; } for(int i=0; i<k; i++){ swap(who[x[i]], who[y[i]]); swap(gde[who[x[i]]], gde[who[y[i]]]); } for(int i=0; i<m; i++) p[i] = q[i] = 0; int g = 0; for(int i=0; i<n; i++){ if(gde[i] != i){ swap(trenwho[x[g]], trenwho[y[g]]); swap(tren[trenwho[x[g]]], tren[trenwho[y[g]]]); int u = who[i]; p[g] = tren[i]; q[g] = tren[u]; g++; swap(trenwho[tren[i]], trenwho[tren[u]]); swap(tren[i], tren[u]); swap(who[gde[i]], who[gde[u]]); swap(gde[i], gde[u]); } } return g <= k; } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n = N, m = M; for(int i=0; i<n; i++){ niz[i] = S[i]; } for(int i=0; i<m; i++){ x[i] = X[i]; y[i] = Y[i]; } int l = 0, r = m, res = m; while(l <= r){ int mid = (l+r)/2; if(check(mid)){ res = mid; r = mid-1; } else l = mid+1; } check(res); for(int i=0; i<res; i++){ P[i] = p[i]; Q[i] = q[i]; } return res; }
#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...