# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
727391 | 2023-04-20T14:49:17 Z | vjudge1 | Sorting (IOI15_sorting) | C++11 | 3 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[]) { for (int i = 0; i < M; i++) P[i] = Q[i] = 0; auto solve = [&](int lim) { vector<int> a(M), b(M), ok(N, 0); 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, b[i]); int pos = b[i]; swap(b[a[i]], b[a[b[i]]]); 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; } } assert(solve(res)); return res; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 296 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 300 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 296 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 300 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 308 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 296 KB | Output is correct |
3 | Correct | 1 ms | 304 KB | Output is correct |
4 | Correct | 1 ms | 312 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Incorrect | 1 ms | 212 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 296 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 300 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 308 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 296 KB | Output is correct |
15 | Correct | 1 ms | 304 KB | Output is correct |
16 | Correct | 1 ms | 312 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Incorrect | 1 ms | 212 KB | Output isn't correct |
19 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 436 KB | Output is correct |
2 | Correct | 3 ms | 468 KB | Output is correct |
3 | Incorrect | 2 ms | 468 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 436 KB | Output is correct |
2 | Correct | 3 ms | 468 KB | Output is correct |
3 | Incorrect | 2 ms | 468 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |