# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1092717 | 2024-09-24T19:57:29 Z | triplem5ds | 정렬하기 (IOI15_sorting) | C++14 | 165 ms | 20244 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[]) { vector<pair<int, int>> ans; auto check = [&](int prefix) { ans.clear(); vector<int> vec(N), vis(N, 0), pos(N); copy(S, S + N, vec.begin()); for (int i = 0; i < prefix; i++) swap(vec[X[i]], vec[Y[i]]); for (int i = 0; i < N; i++) { int cur = i; vis[cur] = 1; while (!vis[vec[cur]]) { ans.push_back({ cur,vec[cur] }); cur = vec[cur]; vis[cur] = 1; } } return ans.size() <= prefix; }; int lo = 0, hi = M; while (lo < hi) { int md = lo + (hi - lo) / 2; if (check(md)) hi = md; else lo = md + 1; } check(lo); reverse(ans.begin(), ans.end()); while (ans.size() <= lo) ans.push_back({ 0, 0 }); vector<int> pos(N), vec(N); for (int i = 0; i < N; i++) { pos[i] = vec[i] = i; } for (int i = lo - 1; i >= 0; --i) { P[i] = pos[ans[i].first]; Q[i] = pos[ans[i].second]; swap(pos[vec[X[i]]], pos[vec[Y[i]]]); swap(vec[X[i]], vec[Y[i]]); } return lo; } /* let's say I have an array of pairs(a, b) let's do all swaps of this array at the end of the swaps what I have is the initial position and the final position so */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 432 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 344 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 432 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 344 KB | Output is correct |
6 | Correct | 0 ms | 348 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 | 0 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 468 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 432 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 344 KB | Output is correct |
6 | Correct | 0 ms | 348 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 | 0 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 344 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 468 KB | Output is correct |
16 | Correct | 1 ms | 348 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 1 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 | 448 KB | Output is correct |
22 | Correct | 1 ms | 604 KB | Output is correct |
23 | Correct | 1 ms | 604 KB | Output is correct |
24 | Correct | 1 ms | 604 KB | Output is correct |
25 | Correct | 1 ms | 612 KB | Output is correct |
26 | Correct | 1 ms | 612 KB | Output is correct |
27 | Correct | 1 ms | 612 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 616 KB | Output is correct |
2 | Correct | 1 ms | 532 KB | Output is correct |
3 | Correct | 1 ms | 616 KB | Output is correct |
4 | Correct | 1 ms | 616 KB | Output is correct |
5 | Correct | 1 ms | 616 KB | Output is correct |
6 | Correct | 1 ms | 616 KB | Output is correct |
7 | Correct | 1 ms | 616 KB | Output is correct |
8 | Correct | 1 ms | 616 KB | Output is correct |
9 | Correct | 1 ms | 616 KB | Output is correct |
10 | Correct | 1 ms | 616 KB | Output is correct |
11 | Correct | 1 ms | 616 KB | Output is correct |
12 | Correct | 1 ms | 616 KB | Output is correct |
13 | Correct | 1 ms | 616 KB | Output is correct |
14 | Correct | 1 ms | 360 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 616 KB | Output is correct |
2 | Correct | 1 ms | 532 KB | Output is correct |
3 | Correct | 1 ms | 616 KB | Output is correct |
4 | Correct | 1 ms | 616 KB | Output is correct |
5 | Correct | 1 ms | 616 KB | Output is correct |
6 | Correct | 1 ms | 616 KB | Output is correct |
7 | Correct | 1 ms | 616 KB | Output is correct |
8 | Correct | 1 ms | 616 KB | Output is correct |
9 | Correct | 1 ms | 616 KB | Output is correct |
10 | Correct | 1 ms | 616 KB | Output is correct |
11 | Correct | 1 ms | 616 KB | Output is correct |
12 | Correct | 1 ms | 616 KB | Output is correct |
13 | Correct | 1 ms | 616 KB | Output is correct |
14 | Correct | 1 ms | 360 KB | Output is correct |
15 | Correct | 129 ms | 17912 KB | Output is correct |
16 | Correct | 135 ms | 18332 KB | Output is correct |
17 | Correct | 144 ms | 19304 KB | Output is correct |
18 | Correct | 62 ms | 17864 KB | Output is correct |
19 | Correct | 111 ms | 18884 KB | Output is correct |
20 | Correct | 115 ms | 19140 KB | Output is correct |
21 | Correct | 120 ms | 19140 KB | Output is correct |
22 | Correct | 122 ms | 14720 KB | Output is correct |
23 | Correct | 146 ms | 20052 KB | Output is correct |
24 | Correct | 165 ms | 19724 KB | Output is correct |
25 | Correct | 148 ms | 19408 KB | Output is correct |
26 | Correct | 105 ms | 18136 KB | Output is correct |
27 | Correct | 102 ms | 17868 KB | Output is correct |
28 | Correct | 144 ms | 19524 KB | Output is correct |
29 | Correct | 142 ms | 19056 KB | Output is correct |
30 | Correct | 74 ms | 17492 KB | Output is correct |
31 | Correct | 143 ms | 19600 KB | Output is correct |
32 | Correct | 141 ms | 19380 KB | Output is correct |
33 | Correct | 148 ms | 19848 KB | Output is correct |
34 | Correct | 145 ms | 19736 KB | Output is correct |
35 | Correct | 115 ms | 18868 KB | Output is correct |
36 | Correct | 43 ms | 16812 KB | Output is correct |
37 | Correct | 150 ms | 20244 KB | Output is correct |
38 | Correct | 154 ms | 19412 KB | Output is correct |
39 | Correct | 148 ms | 19520 KB | Output is correct |