Submission #225877

#TimeUsernameProblemLanguageResultExecution timeMemory
225877staniewzkiSorting (IOI15_sorting)C++17
100 / 100
442 ms11492 KiB
#include<bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < n; i++) #include "sorting.h" int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { auto check = [&](int R) { vector<int> s(N), ws(N), wf(N); REP(i, N) s[i] = S[i]; auto f = s; REP(i, R) swap(f[X[i]], f[Y[i]]); REP(i, N) { ws[S[i]] = i; wf[f[i]] = i; } int j = 0; REP(i, R) { int &p = s[X[i]], &q = s[Y[i]]; swap(p, q); swap(ws[p], ws[q]); while(j < N && j == f[j]) j++; if(j < N) { int &a = ws[j], &b = ws[f[j]], &x = wf[j], &y = wf[f[j]]; P[i] = a, Q[i] = b; swap(a, b), swap(s[a], s[b]); swap(x, y), swap(f[x], f[y]); } else P[i] = Q[i] = 0; } REP(i, N) if(i != s[i]) return false; return true; }; int l = 0, r = M; while(l < r) { int m = (l + r) / 2; if(check(m)) r = m; else l = m + 1; } check(l); return l; }
#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...