# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
727394 | 2023-04-20T14:57:19 Z | vjudge1 | Sorting (IOI15_sorting) | C++11 | 2 ms | 468 KB |
#include "sorting.h" #include <bits/stdc++.h> using namespace std; int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { auto solve = [&](int lim) { vector<int> a(M), b(M); for (int i = 0; i < N; i++) a[i] = S[i]; for (int i = 0; i < lim; i++) swap(a[X[i]], a[Y[i]]); for (int i = 0; i < N; i++) b[a[i]] = i; vector<pair<int, int>> changes; for (int i = 0; i < N; i++) { if (a[i] != i) { changes.emplace_back(i, a[i]); int pos = b[i]; swap(b[a[i]], b[a[pos]]); swap(a[i], a[pos]); } } if (changes.size() > lim) return 0; for (int i = 0; i < N; i++) a[i] = S[i]; for (int i = 0; i < N; i++) b[a[i]] = i; for (int i = 0; i < changes.size(); i++) { swap(b[a[X[i]]], b[a[Y[i]]]); swap(a[X[i]], a[Y[i]]); P[i] = b[changes[i].first]; Q[i] = b[changes[i].second]; } return 1; }; int l = 0, r = M, res = -1; while (l <= r) { if (solve(l + r >> 1)) { res = l + r >> 1; r = (l + r >> 1) - 1; } else { l = (l + r >> 1) + 1; } } for (int i = 0; i < M; i++) P[i] = Q[i] = 0; assert(solve(res)); return res; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 300 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 296 KB | Output is correct |
5 | Incorrect | 1 ms | 212 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 300 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 296 KB | Output is correct |
5 | Incorrect | 1 ms | 212 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Incorrect | 1 ms | 300 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 300 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 296 KB | Output is correct |
5 | Incorrect | 1 ms | 212 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 468 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 468 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |