Submission #426083

#TimeUsernameProblemLanguageResultExecution timeMemory
426083_fractalSorting (IOI15_sorting)C++14
20 / 100
50 ms332 KiB
#include "sorting.h" #include <iostream> #include <algorithm> using namespace std; int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { int A[N], pos[N]; for (int i = 0; i < N; ++i) A[i] = i; for (int i = M - 1; i >= 0; --i) swap(A[X[i]], A[Y[i]]); for (int i = 0; i < M; ++i) { P[i] = Q[i] = 0; bool f = 1; for (int j = 1; j < N; ++j) if (S[j - 1] > S[j]) f = 0; if (f) return i; swap(S[X[i]], S[Y[i]]); swap(A[X[i]], A[Y[i]]); f = 1; for (int j = 1; j < N; ++j) if (S[j - 1] > S[j]) f = 0; if (f) { Q[i] = P[i] = 0; return i + 1; } for (int j = 0; j < N; ++j) pos[A[j]] = j; for (int j = 0; j < N; ++j) { if (pos[S[j]] != j) { Q[i] = j, P[i] = pos[S[j]]; break; } } swap(S[Q[i]], S[P[i]]); } return M; }
#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...