# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
71489 | 2018-08-24T22:58:25 Z | RezwanArefin01 | 정렬하기 (IOI15_sorting) | C++17 | 282 ms | 13176 KB |
#include <bits/stdc++.h> #include "sorting.h" using namespace std; const int N = 2e5 + 10; int p[N], pos[N]; int tp[N], tq[N]; int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { bool flag = 1; for(int i = 0; i < N - 1; i++) flag &= S[i] < S[i + 1]; if(flag) return 0; auto check = [&](int t) { for(int i = 0; i < N; i++) p[i] = S[i]; for(int i = 0; i <= t; i++) swap(p[X[i]], p[Y[i]]); for(int i = 0; i < N; i++) pos[p[i]] = i; int cnt = 0; for(int i = 0; i < N; i++) { if(p[i] != i) { tp[cnt] = i; tq[cnt++] = p[i]; int x = p[i]; swap(p[i], p[pos[i]]); pos[x] = pos[i]; } } return cnt; }; int lo = 0, hi = M, ans = -1; while(lo <= hi) { int mid = lo + hi >> 1; if(check(mid) <= mid + 1) ans = mid, hi = mid - 1; else lo = mid + 1; } for(int i = check(ans); i <= ans; i++) tp[i] = tq[i] = 0; for(int i = 0; i < N; i++) p[i] = S[i]; for(int i = 0; i < N; i++) pos[p[i]] = i; auto fn = [&](int i, int j) { pos[p[i]] = j; pos[p[j]] = i; swap(p[i], p[j]); }; for(int i = 0; i <= ans; i++) { fn(X[i], Y[i]); P[i] = pos[tp[i]]; Q[i] = pos[tq[i]]; fn(P[i], Q[i]); } return 1 + ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 3 ms | 384 KB | Output is correct |
10 | Correct | 3 ms | 384 KB | Output is correct |
11 | Correct | 3 ms | 384 KB | Output is correct |
12 | Correct | 3 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 3 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 3 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 3 ms | 384 KB | Output is correct |
10 | Correct | 3 ms | 384 KB | Output is correct |
11 | Correct | 3 ms | 384 KB | Output is correct |
12 | Correct | 3 ms | 384 KB | Output is correct |
13 | Correct | 3 ms | 384 KB | Output is correct |
14 | Correct | 3 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 3 ms | 384 KB | Output is correct |
17 | Correct | 2 ms | 384 KB | Output is correct |
18 | Correct | 3 ms | 384 KB | Output is correct |
19 | Correct | 3 ms | 384 KB | Output is correct |
20 | Correct | 3 ms | 384 KB | Output is correct |
21 | Correct | 4 ms | 512 KB | Output is correct |
22 | Correct | 3 ms | 512 KB | Output is correct |
23 | Correct | 4 ms | 512 KB | Output is correct |
24 | Correct | 4 ms | 512 KB | Output is correct |
25 | Correct | 3 ms | 512 KB | Output is correct |
26 | Correct | 3 ms | 512 KB | Output is correct |
27 | Correct | 3 ms | 512 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 512 KB | Output is correct |
3 | Correct | 3 ms | 512 KB | Output is correct |
4 | Correct | 3 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 3 ms | 512 KB | Output is correct |
7 | Correct | 4 ms | 512 KB | Output is correct |
8 | Correct | 4 ms | 512 KB | Output is correct |
9 | Correct | 4 ms | 512 KB | Output is correct |
10 | Correct | 4 ms | 512 KB | Output is correct |
11 | Correct | 4 ms | 512 KB | Output is correct |
12 | Correct | 4 ms | 512 KB | Output is correct |
13 | Correct | 3 ms | 512 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 512 KB | Output is correct |
3 | Correct | 3 ms | 512 KB | Output is correct |
4 | Correct | 3 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 3 ms | 512 KB | Output is correct |
7 | Correct | 4 ms | 512 KB | Output is correct |
8 | Correct | 4 ms | 512 KB | Output is correct |
9 | Correct | 4 ms | 512 KB | Output is correct |
10 | Correct | 4 ms | 512 KB | Output is correct |
11 | Correct | 4 ms | 512 KB | Output is correct |
12 | Correct | 4 ms | 512 KB | Output is correct |
13 | Correct | 3 ms | 512 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 178 ms | 11640 KB | Output is correct |
16 | Correct | 223 ms | 11824 KB | Output is correct |
17 | Correct | 230 ms | 12476 KB | Output is correct |
18 | Correct | 36 ms | 5368 KB | Output is correct |
19 | Correct | 173 ms | 10564 KB | Output is correct |
20 | Correct | 196 ms | 11000 KB | Output is correct |
21 | Correct | 186 ms | 11000 KB | Output is correct |
22 | Correct | 200 ms | 12792 KB | Output is correct |
23 | Correct | 234 ms | 13048 KB | Output is correct |
24 | Correct | 267 ms | 12688 KB | Output is correct |
25 | Correct | 264 ms | 12636 KB | Output is correct |
26 | Correct | 187 ms | 10492 KB | Output is correct |
27 | Correct | 174 ms | 9788 KB | Output is correct |
28 | Correct | 226 ms | 12536 KB | Output is correct |
29 | Correct | 262 ms | 11900 KB | Output is correct |
30 | Correct | 137 ms | 8928 KB | Output is correct |
31 | Correct | 259 ms | 12152 KB | Output is correct |
32 | Correct | 221 ms | 12668 KB | Output is correct |
33 | Correct | 252 ms | 12792 KB | Output is correct |
34 | Correct | 237 ms | 12664 KB | Output is correct |
35 | Correct | 193 ms | 10532 KB | Output is correct |
36 | Correct | 44 ms | 7288 KB | Output is correct |
37 | Correct | 282 ms | 13176 KB | Output is correct |
38 | Correct | 231 ms | 12552 KB | Output is correct |
39 | Correct | 258 ms | 12796 KB | Output is correct |