Submission #426016

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

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:31:13: warning: declaration of 'i' shadows a previous local [-Wshadow]
   31 |    for (int i = 1; i < N; ++i)
      |             ^
sorting.cpp:17:12: note: shadowed declaration is here
   17 |   for (int i = 0; i < M; ++i) {
      |            ^
#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...