# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
707037 | 2023-03-08T10:15:20 Z | marvinthang | 정렬하기 (IOI15_sorting) | C++17 | 197 ms | 12476 KB |
#include "sorting.h" #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i) int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { auto check = [&] (int r, bool trace = false) { vector <int> perm(S, S + N); REP(i, r) swap(perm[X[i]], perm[Y[i]]); vector <int> pos(N); REP(i, N) pos[perm[i]] = i; vector <pair <int, int>> swaps; auto __swap = [&] (int i, int j) { swap(perm[i], perm[j]); swap(pos[perm[i]], pos[perm[j]]); }; REP(i, N) { if (perm[i] != i) { swaps.push_back(make_pair(perm[i], i)); __swap(i, pos[i]); } } if (!trace) return swaps.size() <= r; while (swaps.size() < r) swaps.push_back(make_pair(0, 0)); copy(S, S + N, perm.begin()); REP(i, N) pos[perm[i]] = i; REP(i, r) { __swap(X[i], Y[i]); P[i] = pos[swaps[i].fi]; Q[i] = pos[swaps[i].se]; __swap(P[i], Q[i]); } return true; }; int l = 0, r = N; while (l < r) { int m = l + r >> 1; if (check(m)) r = m; else l = m + 1; } check(l, true); return l; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 316 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 0 ms | 316 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Correct | 1 ms | 340 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 1 ms | 340 KB | Output is correct |
24 | Correct | 1 ms | 340 KB | Output is correct |
25 | Correct | 1 ms | 340 KB | Output is correct |
26 | Correct | 1 ms | 340 KB | Output is correct |
27 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 2 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 2 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 2 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 2 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 165 ms | 11296 KB | Output is correct |
16 | Correct | 170 ms | 11584 KB | Output is correct |
17 | Correct | 195 ms | 11908 KB | Output is correct |
18 | Correct | 56 ms | 7876 KB | Output is correct |
19 | Correct | 131 ms | 9620 KB | Output is correct |
20 | Correct | 134 ms | 11356 KB | Output is correct |
21 | Correct | 131 ms | 11428 KB | Output is correct |
22 | Correct | 163 ms | 12084 KB | Output is correct |
23 | Correct | 188 ms | 12296 KB | Output is correct |
24 | Correct | 194 ms | 12192 KB | Output is correct |
25 | Correct | 192 ms | 12112 KB | Output is correct |
26 | Correct | 131 ms | 11416 KB | Output is correct |
27 | Correct | 136 ms | 9564 KB | Output is correct |
28 | Correct | 186 ms | 12128 KB | Output is correct |
29 | Correct | 183 ms | 11708 KB | Output is correct |
30 | Correct | 90 ms | 9200 KB | Output is correct |
31 | Correct | 177 ms | 11836 KB | Output is correct |
32 | Correct | 197 ms | 12016 KB | Output is correct |
33 | Correct | 197 ms | 12208 KB | Output is correct |
34 | Correct | 179 ms | 12128 KB | Output is correct |
35 | Correct | 135 ms | 9652 KB | Output is correct |
36 | Correct | 49 ms | 7280 KB | Output is correct |
37 | Correct | 196 ms | 12476 KB | Output is correct |
38 | Correct | 182 ms | 12056 KB | Output is correct |
39 | Correct | 192 ms | 12164 KB | Output is correct |