Submission #286714

#TimeUsernameProblemLanguageResultExecution timeMemory
286714OzySorting (IOI15_sorting)C++17
Compilation error
0 ms0 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,pos) 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]; } } } return seg; }

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:67:13: error: 'pos' was not declared in this scope; did you mean 'pas'?
   67 |     rep(i,0,pos) swap(doble[x[i]],doble[y[i]]);
      |             ^~~
sorting.cpp:4:43: note: in definition of macro 'rep'
    4 | #define rep(i,a,b) for(int i = (a); i <= (b); i++)
      |                                           ^