Submission #48223

#TimeUsernameProblemLanguageResultExecution timeMemory
48223cheater2kSorting (IOI15_sorting)C++17
0 / 100
18 ms640 KiB
#include "sorting.h" #include <bits/stdc++.h> using namespace std; const int MAXN = 2005; int n, m; int s[MAXN], pos[MAXN]; int cnt[MAXN]; void do_swap(int x, int y) { int p = s[x], q = s[y]; swap(pos[p], pos[q]); swap(s[x], s[y]); } 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) { s[i] = S[i]; pos[s[i]] = i; } for (int i = 0; i < m; ++i) { ++cnt[X[i]]; ++cnt[Y[i]]; } for (int i = 0; i < m; ++i) { do_swap(X[i], Y[i]); --cnt[X[i]]; --cnt[Y[i]]; bool found = false; for (int j = 0; j < n; ++j) { if (pos[j] != j && cnt[j] == 0) { found = true; P[i] = j; Q[i] = pos[j]; do_swap(j, pos[j]); break; } } if (!found) P[i] = Q[i] = 0, do_swap(0, 0); } for (int i = 0; i < n; ++i) assert(s[i] == 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...