Submission #48233

#TimeUsernameProblemLanguageResultExecution timeMemory
48233cheater2kSorting (IOI15_sorting)C++17
0 / 100
4 ms640 KiB
#include "sorting.h" #include <bits/stdc++.h> using namespace std; const int MAXN = 200005; int n, m; int s[MAXN]; int pa[MAXN], pb[MAXN], a[MAXN], b[MAXN], pos[MAXN]; int x[MAXN * 3], y[MAXN * 3]; vector < pair<int,int> > vres; bool check(int k) { vres.clear(); for (int i = 0; i < n; ++i) { b[i] = i; } for (int i = 0; i < k; ++i) { swap(b[x[i]], b[y[i]]); // swap positions } // the swaps must satisfy: s[i] = b[i] for (int i = 0; i < n; ++i) { pb[s[i]] = b[i]; pa[b[i]] = s[i]; } for (int i = 0; i < n; ++i) { if (pa[i] != i) { // TODO: swap i, pb[i] int j = pb[i]; int p = pa[i], q = pa[j]; vres.push_back({p, q}); // values, not positions swap(pa[i], pa[j]); pb[q] = i; pb[p] = j; } } // trace the positions for (int i = 0; i < n; ++i) a[i] = s[i], pos[a[i]] = i; for (int i = 0; i < k; ++i) { // swap a[x[i]], a[y[i]] pos[a[x[i]]] = y[i]; pos[a[y[i]]] = x[i]; swap(a[x[i]], a[y[i]]); // trace if (i < (int)vres.size()) { vres[i] = {pos[vres[i].first], pos[vres[i].second]}; } } for (int i = (int)vres.size(); i < k; ++i) { vres.push_back({0, 0}); } return vres.size() == k; } 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]; for (int i = 0; i < m; ++i) x[i] = X[i], y[i] = Y[i]; int low = 0, high = m; while(low < high) { int mid = ((low + high) >> 1); if (check(mid)) high = mid; else low = mid + 1; } check(low); for (int i = 0; i < low; ++i) { P[i] = vres[i].first; Q[i] = vres[i].second; } return low; }

Compilation message (stderr)

sorting.cpp: In function 'bool check(int)':
sorting.cpp:58:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  return vres.size() == k;
         ~~~~~~~~~~~~^~~~
#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...