# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
307490 | 2020-09-28T10:54:36 Z | lohacho | 정렬하기 (IOI15_sorting) | C++14 | 490 ms | 22784 KB |
#include "sorting.h" #include <bits/stdc++.h> using namespace std; using LL = long long; const int INF = (int)1e9 + 7; const int NS = (int)2e5 + 4; int mov[NS], Index[NS], pos[NS], S_save[NS], ba[NS]; int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { for(int i = 0; i < N; ++i){ S_save[i] = S[i]; } int low = 0, high = N - 1, mid; function < int() > can_sort = [&](){ for(int i = 0; i < N; ++i){ S[i] = S_save[i]; mov[i] = i; Index[S[i]] = i; ba[i] = S[i]; pos[S[i]] = i; } for(int i = mid - 1; i >= 0; --i){ swap(mov[X[i]], mov[Y[i]]); } int diff = 0; for(int i = 0; i < mid; ++i){ while(diff < N && mov[diff] == S[diff]) ++diff; swap(Index[ba[X[i]]], Index[ba[Y[i]]]); swap(ba[X[i]], ba[Y[i]]); if(diff >= N){ P[i] = Q[i] = 0; } else{ P[i] = Index[S[diff]], Q[i] = Index[mov[diff]]; swap(Index[S[diff]], Index[mov[diff]]); swap(ba[P[i]], ba[Q[i]]); swap(S[diff], S[pos[mov[diff]]]); swap(pos[S[diff]], pos[S[pos[mov[diff]]]]); } } while(diff < N && mov[diff] == S[diff]) ++diff; if(diff >= N) return 1; else return 0; }; while(low < high){ mid = (low + high) >> 1; for(int i = 0; i < N; ++i) P[i] = Q[i] = 0; if(can_sort()){ high = mid; } else{ low = mid + 1; } } mid = low; can_sort(); return low; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 0 ms | 384 KB | Output is correct |
9 | Correct | 0 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 384 KB | Output is correct |
12 | Correct | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 0 ms | 384 KB | Output is correct |
9 | Correct | 0 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 384 KB | Output is correct |
12 | Correct | 1 ms | 384 KB | Output is correct |
13 | Correct | 0 ms | 384 KB | Output is correct |
14 | Correct | 1 ms | 384 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
16 | Correct | 1 ms | 384 KB | Output is correct |
17 | Correct | 1 ms | 384 KB | Output is correct |
18 | Correct | 1 ms | 384 KB | Output is correct |
19 | Correct | 1 ms | 384 KB | Output is correct |
20 | Correct | 0 ms | 384 KB | Output is correct |
21 | Correct | 2 ms | 512 KB | Output is correct |
22 | Correct | 2 ms | 640 KB | Output is correct |
23 | Correct | 2 ms | 640 KB | Output is correct |
24 | Correct | 2 ms | 640 KB | Output is correct |
25 | Correct | 1 ms | 640 KB | Output is correct |
26 | Correct | 1 ms | 640 KB | Output is correct |
27 | Correct | 2 ms | 640 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 512 KB | Output is correct |
2 | Correct | 2 ms | 596 KB | Output is correct |
3 | Correct | 2 ms | 544 KB | Output is correct |
4 | Correct | 2 ms | 512 KB | Output is correct |
5 | Correct | 1 ms | 512 KB | Output is correct |
6 | Correct | 2 ms | 640 KB | Output is correct |
7 | Correct | 2 ms | 640 KB | Output is correct |
8 | Correct | 3 ms | 512 KB | Output is correct |
9 | Correct | 2 ms | 512 KB | Output is correct |
10 | Correct | 3 ms | 512 KB | Output is correct |
11 | Correct | 2 ms | 512 KB | Output is correct |
12 | Correct | 2 ms | 512 KB | Output is correct |
13 | Correct | 3 ms | 512 KB | Output is correct |
14 | Correct | 1 ms | 512 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 512 KB | Output is correct |
2 | Correct | 2 ms | 596 KB | Output is correct |
3 | Correct | 2 ms | 544 KB | Output is correct |
4 | Correct | 2 ms | 512 KB | Output is correct |
5 | Correct | 1 ms | 512 KB | Output is correct |
6 | Correct | 2 ms | 640 KB | Output is correct |
7 | Correct | 2 ms | 640 KB | Output is correct |
8 | Correct | 3 ms | 512 KB | Output is correct |
9 | Correct | 2 ms | 512 KB | Output is correct |
10 | Correct | 3 ms | 512 KB | Output is correct |
11 | Correct | 2 ms | 512 KB | Output is correct |
12 | Correct | 2 ms | 512 KB | Output is correct |
13 | Correct | 3 ms | 512 KB | Output is correct |
14 | Correct | 1 ms | 512 KB | Output is correct |
15 | Correct | 353 ms | 20064 KB | Output is correct |
16 | Correct | 375 ms | 20600 KB | Output is correct |
17 | Correct | 445 ms | 21624 KB | Output is correct |
18 | Correct | 107 ms | 18556 KB | Output is correct |
19 | Correct | 262 ms | 20856 KB | Output is correct |
20 | Correct | 338 ms | 21496 KB | Output is correct |
21 | Correct | 312 ms | 21472 KB | Output is correct |
22 | Correct | 350 ms | 17016 KB | Output is correct |
23 | Correct | 357 ms | 22520 KB | Output is correct |
24 | Correct | 474 ms | 22052 KB | Output is correct |
25 | Correct | 470 ms | 21880 KB | Output is correct |
26 | Correct | 286 ms | 21500 KB | Output is correct |
27 | Correct | 282 ms | 20856 KB | Output is correct |
28 | Correct | 443 ms | 22008 KB | Output is correct |
29 | Correct | 395 ms | 21624 KB | Output is correct |
30 | Correct | 193 ms | 20472 KB | Output is correct |
31 | Correct | 462 ms | 22136 KB | Output is correct |
32 | Correct | 382 ms | 21624 KB | Output is correct |
33 | Correct | 462 ms | 22024 KB | Output is correct |
34 | Correct | 424 ms | 22092 KB | Output is correct |
35 | Correct | 288 ms | 20600 KB | Output is correct |
36 | Correct | 90 ms | 19832 KB | Output is correct |
37 | Correct | 490 ms | 22784 KB | Output is correct |
38 | Correct | 448 ms | 21808 KB | Output is correct |
39 | Correct | 426 ms | 22036 KB | Output is correct |