Submission #114698

#TimeUsernameProblemLanguageResultExecution timeMemory
114698arman_ferdousSorting (IOI15_sorting)C++17
20 / 100
1053 ms512 KiB
#include "sorting.h" #include <bits/stdc++.h> using namespace std; const int N = 2e5+100; int n, ss[N], m, x[N], y[N], p[N], q[N]; int tmp[N]; int solve(int M) { for(int i = 0; i < n; i++) tmp[i] = ss[i]; for(int i = 0; i < M; i++) swap(tmp[x[i]], tmp[y[i]]); int cur = 0, R = 0; for(int i = 0; i < n; ) { if(tmp[i] == i) { i++; continue; } int pp = i, qq = tmp[i]; if(cur >= M) return -1; for(int j = M-1; j > cur; j--) { if((x[j] == pp && y[j] == qq) || (x[j] == qq && y[j] == pp)) swap(pp, qq); else { if(x[j] == pp) pp = y[j]; else if(y[j] == pp) pp = x[j]; if(x[j] == qq) qq = y[j]; else if(y[j] == qq) qq = x[j]; } } p[R] = pp, q[R] = qq; R++, cur++; swap(tmp[i], tmp[tmp[i]]); } return R; } 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++) ss[i] = S[i]; for(int i = 0; i < m; i++) x[i] = X[i], y[i] = Y[i]; // int lo = 0, hi = M, idx; // while(lo <= hi) { // int mid = (lo + hi) >> 1; // int R = solve(mid); // if(R == -1) lo = mid+1; // else idx = mid, hi = mid-1; // } for(int i = 0; i <= M; i++) if(solve(i) == i) { for(int j = 0; j < i; j++) P[j] = p[j], Q[j] = q[j]; return i; } // int R = solve(idx); // for(int i = 0; i < R; i++) // P[i] = p[i], Q[i] = q[i]; assert(0==1); }
#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...