# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1075257 | 2024-08-25T21:40:36 Z | ArthuroWich | Sorting (IOI15_sorting) | C++17 | 162 ms | 32224 KB |
#include "sorting.h" #include<bits/stdc++.h> using namespace std; vector<pair<int, int>> ans, xy, swaps; bool check(vector<int> p, int m, int n) { int s = 0; vector<int> e = p; vector<int> co(n, 0); for (int i = 0; i < n; i++) { co[p[i]] = i; } for (int i = 0; i < m; i++) { swap(p[xy[i].first], p[xy[i].second]); } for (int i = 0; i < n; i++) { if (p[i] == i) { continue; } while(p[i] != i) { int j = p[i]; swaps.push_back({p[i], p[j]}); swap(p[i], p[j]); s++; } } if (swaps.size() > m) { return 0; } while(swaps.size() < m) { swaps.push_back({0, 0}); } for (int i = 0; i < m; i++) { swap(co[e[xy[i].first]], co[e[xy[i].second]]); swap(e[xy[i].first], e[xy[i].second]); auto [x, y] = swaps[i]; swaps[i] = {co[x], co[y]}; swap(e[co[x]], e[co[y]]); swap(co[x], co[y]); } return s <= m; } int findSwapPairs(int n, int A[], int M, int X[], int Y[], int P[], int Q[]) { vector<int> p(n); for (int i = 0; i < n; i++) { p[i] = A[i]; } for (int i = 0; i < M; i++) { xy.push_back({X[i], Y[i]}); } int l = 0, r = M; while(l < r) { int m = (l+r)/2; swaps.clear(); if (check(p, m, n)) { r = m; ans = swaps; } else { l = m+1; } } for (int i = 0; i < ans.size(); i++) { P[i] = ans[i].first; Q[i] = ans[i].second; } return ans.size(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 344 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 432 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 344 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 432 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 444 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 604 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 344 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 432 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 444 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 1 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 604 KB | Output is correct |
16 | Correct | 0 ms | 348 KB | Output is correct |
17 | Correct | 1 ms | 348 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 348 KB | Output is correct |
20 | Correct | 0 ms | 348 KB | Output is correct |
21 | Correct | 1 ms | 860 KB | Output is correct |
22 | Correct | 1 ms | 860 KB | Output is correct |
23 | Correct | 2 ms | 860 KB | Output is correct |
24 | Correct | 2 ms | 856 KB | Output is correct |
25 | Correct | 1 ms | 860 KB | Output is correct |
26 | Correct | 1 ms | 860 KB | Output is correct |
27 | Correct | 1 ms | 860 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 604 KB | Output is correct |
2 | Correct | 1 ms | 604 KB | Output is correct |
3 | Correct | 2 ms | 604 KB | Output is correct |
4 | Correct | 1 ms | 604 KB | Output is correct |
5 | Correct | 1 ms | 628 KB | Output is correct |
6 | Correct | 1 ms | 604 KB | Output is correct |
7 | Correct | 1 ms | 704 KB | Output is correct |
8 | Correct | 1 ms | 604 KB | Output is correct |
9 | Correct | 1 ms | 608 KB | Output is correct |
10 | Correct | 1 ms | 604 KB | Output is correct |
11 | Correct | 1 ms | 604 KB | Output is correct |
12 | Correct | 2 ms | 604 KB | Output is correct |
13 | Correct | 1 ms | 600 KB | Output is correct |
14 | Correct | 1 ms | 488 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 604 KB | Output is correct |
2 | Correct | 1 ms | 604 KB | Output is correct |
3 | Correct | 2 ms | 604 KB | Output is correct |
4 | Correct | 1 ms | 604 KB | Output is correct |
5 | Correct | 1 ms | 628 KB | Output is correct |
6 | Correct | 1 ms | 604 KB | Output is correct |
7 | Correct | 1 ms | 704 KB | Output is correct |
8 | Correct | 1 ms | 604 KB | Output is correct |
9 | Correct | 1 ms | 608 KB | Output is correct |
10 | Correct | 1 ms | 604 KB | Output is correct |
11 | Correct | 1 ms | 604 KB | Output is correct |
12 | Correct | 2 ms | 604 KB | Output is correct |
13 | Correct | 1 ms | 600 KB | Output is correct |
14 | Correct | 1 ms | 488 KB | Output is correct |
15 | Correct | 141 ms | 28408 KB | Output is correct |
16 | Correct | 162 ms | 28740 KB | Output is correct |
17 | Correct | 157 ms | 30532 KB | Output is correct |
18 | Correct | 69 ms | 26812 KB | Output is correct |
19 | Correct | 112 ms | 29364 KB | Output is correct |
20 | Correct | 117 ms | 30108 KB | Output is correct |
21 | Correct | 121 ms | 30220 KB | Output is correct |
22 | Correct | 131 ms | 25528 KB | Output is correct |
23 | Correct | 155 ms | 30888 KB | Output is correct |
24 | Correct | 155 ms | 30908 KB | Output is correct |
25 | Correct | 157 ms | 30912 KB | Output is correct |
26 | Correct | 118 ms | 30112 KB | Output is correct |
27 | Correct | 109 ms | 29340 KB | Output is correct |
28 | Correct | 147 ms | 30468 KB | Output is correct |
29 | Correct | 150 ms | 30652 KB | Output is correct |
30 | Correct | 91 ms | 29020 KB | Output is correct |
31 | Correct | 157 ms | 31304 KB | Output is correct |
32 | Correct | 142 ms | 30084 KB | Output is correct |
33 | Correct | 153 ms | 31176 KB | Output is correct |
34 | Correct | 153 ms | 30652 KB | Output is correct |
35 | Correct | 120 ms | 29084 KB | Output is correct |
36 | Correct | 57 ms | 28604 KB | Output is correct |
37 | Correct | 156 ms | 32224 KB | Output is correct |
38 | Correct | 147 ms | 30872 KB | Output is correct |
39 | Correct | 155 ms | 31420 KB | Output is correct |