# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1031253 | 2024-07-22T16:26:25 Z | Andrey | 정렬하기 (IOI15_sorting) | C++14 | 170 ms | 22768 KB |
#include "sorting.h" #include<bits/stdc++.h> using namespace std; vector<int> haha(200001); vector<int> bruh(200001); vector<pair<int,int>> wut(0); int calc(int n) { wut.clear(); for(int i = 0; i < n; i++) { bruh[i] = -1; } int br = 0; for(int i = 0; i < n; i++) { if(bruh[i] == -1) { br++; int p = i; vector<pair<int,int>> wow(0); while(bruh[p] == -1) { bruh[p] = 1; wow.push_back({haha[p],haha[haha[p]]}); p = haha[p]; } wow.pop_back(); for(int j = 0; j < wow.size(); j++) { wut.push_back(wow[j]); } } } return n-br; } int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) { int l = 0,r = n; while(l < r) { int mid = (l+r)/2; for(int j = 0; j < n; j++) { haha[j] = s[j]; } for(int j = 0; j < mid; j++) { swap(haha[x[j]],haha[y[j]]); } if(calc(n) <= mid) { r = mid; } else { l = mid+1; } } for(int j = 0; j < n; j++) { haha[j] = s[j]; } for(int j = 0; j < l; j++) { swap(haha[x[j]],haha[y[j]]); } calc(n); vector<int> pos(n); for(int i = 0; i < n; i++) { haha[i] = s[i]; pos[haha[i]] = i; } for(int i = 0; i < l; i++) { int a = x[i],b = y[i]; swap(pos[haha[a]],pos[haha[b]]); swap(haha[a],haha[b]); if(i >= wut.size()) { p[i] = 0; q[i] = 0; } else { p[i] = pos[wut[i].first]; q[i] = pos[wut[i].second]; swap(haha[pos[wut[i].first]],haha[pos[wut[i].second]]); swap(pos[wut[i].first],pos[wut[i].second]); } } return l; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1884 KB | Output is correct |
2 | Correct | 1 ms | 1884 KB | Output is correct |
3 | Correct | 2 ms | 1884 KB | Output is correct |
4 | Correct | 1 ms | 1884 KB | Output is correct |
5 | Correct | 1 ms | 1884 KB | Output is correct |
6 | Correct | 1 ms | 2136 KB | Output is correct |
7 | Correct | 1 ms | 1884 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1884 KB | Output is correct |
2 | Correct | 1 ms | 1884 KB | Output is correct |
3 | Correct | 2 ms | 1884 KB | Output is correct |
4 | Correct | 1 ms | 1884 KB | Output is correct |
5 | Correct | 1 ms | 1884 KB | Output is correct |
6 | Correct | 1 ms | 2136 KB | Output is correct |
7 | Correct | 1 ms | 1884 KB | Output is correct |
8 | Correct | 1 ms | 1880 KB | Output is correct |
9 | Correct | 1 ms | 2020 KB | Output is correct |
10 | Correct | 1 ms | 1884 KB | Output is correct |
11 | Correct | 1 ms | 1884 KB | Output is correct |
12 | Correct | 1 ms | 1884 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1884 KB | Output is correct |
2 | Correct | 1 ms | 1880 KB | Output is correct |
3 | Correct | 1 ms | 1884 KB | Output is correct |
4 | Correct | 1 ms | 1884 KB | Output is correct |
5 | Correct | 1 ms | 1884 KB | Output is correct |
6 | Correct | 1 ms | 1884 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1884 KB | Output is correct |
2 | Correct | 1 ms | 1884 KB | Output is correct |
3 | Correct | 2 ms | 1884 KB | Output is correct |
4 | Correct | 1 ms | 1884 KB | Output is correct |
5 | Correct | 1 ms | 1884 KB | Output is correct |
6 | Correct | 1 ms | 2136 KB | Output is correct |
7 | Correct | 1 ms | 1884 KB | Output is correct |
8 | Correct | 1 ms | 1880 KB | Output is correct |
9 | Correct | 1 ms | 2020 KB | Output is correct |
10 | Correct | 1 ms | 1884 KB | Output is correct |
11 | Correct | 1 ms | 1884 KB | Output is correct |
12 | Correct | 1 ms | 1884 KB | Output is correct |
13 | Correct | 1 ms | 1884 KB | Output is correct |
14 | Correct | 1 ms | 1880 KB | Output is correct |
15 | Correct | 1 ms | 1884 KB | Output is correct |
16 | Correct | 1 ms | 1884 KB | Output is correct |
17 | Correct | 1 ms | 1884 KB | Output is correct |
18 | Correct | 1 ms | 1884 KB | Output is correct |
19 | Correct | 1 ms | 1884 KB | Output is correct |
20 | Correct | 1 ms | 1880 KB | Output is correct |
21 | Correct | 2 ms | 2140 KB | Output is correct |
22 | Correct | 1 ms | 2140 KB | Output is correct |
23 | Correct | 1 ms | 2136 KB | Output is correct |
24 | Correct | 1 ms | 2140 KB | Output is correct |
25 | Correct | 2 ms | 2140 KB | Output is correct |
26 | Correct | 2 ms | 2248 KB | Output is correct |
27 | Correct | 2 ms | 2136 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2136 KB | Output is correct |
2 | Correct | 1 ms | 2032 KB | Output is correct |
3 | Correct | 2 ms | 2140 KB | Output is correct |
4 | Correct | 2 ms | 2140 KB | Output is correct |
5 | Correct | 2 ms | 2140 KB | Output is correct |
6 | Correct | 2 ms | 2140 KB | Output is correct |
7 | Correct | 2 ms | 2100 KB | Output is correct |
8 | Correct | 2 ms | 2136 KB | Output is correct |
9 | Correct | 2 ms | 2092 KB | Output is correct |
10 | Correct | 2 ms | 2008 KB | Output is correct |
11 | Correct | 2 ms | 2136 KB | Output is correct |
12 | Correct | 3 ms | 2032 KB | Output is correct |
13 | Correct | 2 ms | 2136 KB | Output is correct |
14 | Correct | 2 ms | 2140 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2136 KB | Output is correct |
2 | Correct | 1 ms | 2032 KB | Output is correct |
3 | Correct | 2 ms | 2140 KB | Output is correct |
4 | Correct | 2 ms | 2140 KB | Output is correct |
5 | Correct | 2 ms | 2140 KB | Output is correct |
6 | Correct | 2 ms | 2140 KB | Output is correct |
7 | Correct | 2 ms | 2100 KB | Output is correct |
8 | Correct | 2 ms | 2136 KB | Output is correct |
9 | Correct | 2 ms | 2092 KB | Output is correct |
10 | Correct | 2 ms | 2008 KB | Output is correct |
11 | Correct | 2 ms | 2136 KB | Output is correct |
12 | Correct | 3 ms | 2032 KB | Output is correct |
13 | Correct | 2 ms | 2136 KB | Output is correct |
14 | Correct | 2 ms | 2140 KB | Output is correct |
15 | Correct | 126 ms | 20368 KB | Output is correct |
16 | Correct | 132 ms | 19696 KB | Output is correct |
17 | Correct | 147 ms | 22408 KB | Output is correct |
18 | Correct | 115 ms | 16536 KB | Output is correct |
19 | Correct | 164 ms | 18736 KB | Output is correct |
20 | Correct | 157 ms | 20192 KB | Output is correct |
21 | Correct | 146 ms | 20260 KB | Output is correct |
22 | Correct | 119 ms | 16128 KB | Output is correct |
23 | Correct | 135 ms | 22708 KB | Output is correct |
24 | Correct | 139 ms | 22744 KB | Output is correct |
25 | Correct | 131 ms | 22768 KB | Output is correct |
26 | Correct | 149 ms | 20204 KB | Output is correct |
27 | Correct | 141 ms | 18752 KB | Output is correct |
28 | Correct | 156 ms | 21124 KB | Output is correct |
29 | Correct | 164 ms | 21188 KB | Output is correct |
30 | Correct | 143 ms | 17864 KB | Output is correct |
31 | Correct | 148 ms | 21612 KB | Output is correct |
32 | Correct | 160 ms | 20940 KB | Output is correct |
33 | Correct | 154 ms | 22656 KB | Output is correct |
34 | Correct | 138 ms | 21420 KB | Output is correct |
35 | Correct | 161 ms | 18340 KB | Output is correct |
36 | Correct | 109 ms | 16724 KB | Output is correct |
37 | Correct | 168 ms | 22752 KB | Output is correct |
38 | Correct | 152 ms | 21400 KB | Output is correct |
39 | Correct | 170 ms | 22052 KB | Output is correct |