# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1083801 | 2024-09-04T07:35:52 Z | ZeroCool | 정렬하기 (IOI15_sorting) | C++14 | 177 ms | 32152 KB |
#include "sorting.h" #include<bits/stdc++.h> using namespace std; #define ar array #define ll long long #define ld long double vector<ar<int, 2>> 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][0]], p[xy[i][1]]); 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][0]]], co[e[xy[i][1]]]); swap(e[xy[i][0]], e[xy[i][1]]); 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 - 1; while(l <= r) { int m = (l + r)/2; swaps.clear(); if(check(p, m, n)){ r = m - 1; ans = swaps; }else l = m + 1; } for (int i = 0; i < ans.size(); i++) { P[i] = ans[i][0]; Q[i] = ans[i][1]; } return ans.size(); }
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 | 348 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 | 348 KB | Output is correct |
7 | Correct | 0 ms | 436 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 | 348 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 | 348 KB | Output is correct |
7 | Correct | 0 ms | 436 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 | 344 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 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 | 344 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 | 348 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 | 348 KB | Output is correct |
7 | Correct | 0 ms | 436 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 | 344 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Correct | 1 ms | 344 KB | Output is correct |
14 | Correct | 0 ms | 344 KB | Output is correct |
15 | Correct | 0 ms | 348 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 | 344 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 | 712 KB | Output is correct |
23 | Correct | 2 ms | 860 KB | Output is correct |
24 | Correct | 1 ms | 824 KB | Output is correct |
25 | Correct | 1 ms | 860 KB | Output is correct |
26 | Correct | 1 ms | 856 KB | Output is correct |
27 | Correct | 1 ms | 860 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 600 KB | Output is correct |
2 | Correct | 1 ms | 600 KB | Output is correct |
3 | Correct | 1 ms | 512 KB | Output is correct |
4 | Correct | 1 ms | 452 KB | Output is correct |
5 | Correct | 1 ms | 604 KB | Output is correct |
6 | Correct | 1 ms | 604 KB | Output is correct |
7 | Correct | 1 ms | 604 KB | Output is correct |
8 | Correct | 1 ms | 604 KB | Output is correct |
9 | Correct | 1 ms | 604 KB | Output is correct |
10 | Correct | 1 ms | 604 KB | Output is correct |
11 | Correct | 1 ms | 708 KB | Output is correct |
12 | Correct | 1 ms | 604 KB | Output is correct |
13 | Correct | 1 ms | 852 KB | Output is correct |
14 | Correct | 1 ms | 604 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 600 KB | Output is correct |
2 | Correct | 1 ms | 600 KB | Output is correct |
3 | Correct | 1 ms | 512 KB | Output is correct |
4 | Correct | 1 ms | 452 KB | Output is correct |
5 | Correct | 1 ms | 604 KB | Output is correct |
6 | Correct | 1 ms | 604 KB | Output is correct |
7 | Correct | 1 ms | 604 KB | Output is correct |
8 | Correct | 1 ms | 604 KB | Output is correct |
9 | Correct | 1 ms | 604 KB | Output is correct |
10 | Correct | 1 ms | 604 KB | Output is correct |
11 | Correct | 1 ms | 708 KB | Output is correct |
12 | Correct | 1 ms | 604 KB | Output is correct |
13 | Correct | 1 ms | 852 KB | Output is correct |
14 | Correct | 1 ms | 604 KB | Output is correct |
15 | Correct | 144 ms | 28252 KB | Output is correct |
16 | Correct | 160 ms | 28652 KB | Output is correct |
17 | Correct | 166 ms | 30564 KB | Output is correct |
18 | Correct | 69 ms | 26840 KB | Output is correct |
19 | Correct | 112 ms | 29360 KB | Output is correct |
20 | Correct | 129 ms | 30304 KB | Output is correct |
21 | Correct | 124 ms | 30368 KB | Output is correct |
22 | Correct | 143 ms | 25528 KB | Output is correct |
23 | Correct | 165 ms | 30892 KB | Output is correct |
24 | Correct | 176 ms | 30856 KB | Output is correct |
25 | Correct | 177 ms | 30864 KB | Output is correct |
26 | Correct | 126 ms | 30108 KB | Output is correct |
27 | Correct | 122 ms | 29356 KB | Output is correct |
28 | Correct | 170 ms | 30680 KB | Output is correct |
29 | Correct | 168 ms | 30648 KB | Output is correct |
30 | Correct | 90 ms | 28952 KB | Output is correct |
31 | Correct | 159 ms | 31144 KB | Output is correct |
32 | Correct | 155 ms | 30148 KB | Output is correct |
33 | Correct | 174 ms | 31156 KB | Output is correct |
34 | Correct | 164 ms | 30656 KB | Output is correct |
35 | Correct | 118 ms | 29116 KB | Output is correct |
36 | Correct | 62 ms | 28524 KB | Output is correct |
37 | Correct | 173 ms | 32152 KB | Output is correct |
38 | Correct | 161 ms | 30888 KB | Output is correct |
39 | Correct | 171 ms | 31420 KB | Output is correct |