Submission #286721

#TimeUsernameProblemLanguageResultExecution timeMemory
286721OzySorting (IOI15_sorting)C++17
0 / 100
1 ms512 KiB
#include "sorting.h" #include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i = (a); i <= (b); i++) #define debug(a) cout << #a << " = " << a << endl int sum,largo,act,cont; int seg,n,m,w,pas; int s[200001],x[600001],y[600001],doble[200001],visitados[200001]; bool checa(int pos) { rep(i,0,n-1) visitados[i] = 0; rep(i,0,n-1) doble[i] = s[i]; rep(i,0,pos) swap(doble[x[i]],doble[y[i]]); sum = 0; rep(i,0,n-1) { if (visitados[i] == 0) { act = doble[i]; largo = 0; visitados[i] = 1; while (act != i) { largo++; visitados[act] = 1; act = doble[act]; } sum += largo; } } if (sum <= (pos+1)) return true; else return false; } void binaria(int ini, int fin) { int mitad; if (ini <= fin) { mitad = (ini+fin)/2; if (checa(mitad)) { seg = mitad; binaria(ini,mitad-1); } else binaria(mitad+1 ,fin); } } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n = N; m = M; rep(i,0,N) s[i] = S[i]; rep(i,0,M) x[i] = X[i]; rep(i,0,M) y[i] = Y[i]; binaria(0,M-1); rep(i,0,n-1) visitados[i] = 0; rep(i,0,n-1) doble[i] = s[i]; rep(i,0,seg) swap(doble[x[i]],doble[y[i]]); cont = 0; rep(i,0,n-1) { if (visitados[i] == 0) { act = doble[i]; pas = i; visitados[i] = 1; while (act != i) { P[cont] = pas; Q[cont] = act; cont++; visitados[act] = 1; pas = act; act = doble[act]; } } } cerr << seg; return (seg+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...