# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
432991 | 2021-06-18T17:11:33 Z | wiwiho | 정렬하기 (IOI15_sorting) | C++14 | 428 ms | 19728 KB |
#include "sorting.h" #include <bits/stdc++.h> #define printv(a, b) { \ for(auto pv : a) b << pv << " "; \ b << "\n"; \ } #define mp make_pair #define F first #define Sc second #define eb emplace_back using namespace std; typedef long long ll; using pii = pair<int, int>; const ll MOD = 1000000007; vector<pii> ans; bool calc(int n, int S[], int m, int X[], int Y[]){ ans.clear(); vector<int> s(n); for(int i = 0; i < n; i++) s[i] = S[i]; vector<int> num(n); vector<int> pos(n); for(int i = 0; i < n; i++) num[i] = pos[i] = i; for(int i = 0; i < m; i++){ swap(num[pos[X[i]]], num[pos[Y[i]]]); swap(pos[X[i]], pos[Y[i]]); } int cnt = 0; vector<int> now(n), np(n); for(int i = 0; i < n; i++) now[i] = i, np[i] = i; for(int i = 0; i < n; i++){ while(s[i] != num[i]){ if(cnt >= m) return false; swap(now[np[X[cnt]]], now[np[Y[cnt]]]); swap(np[X[cnt]], np[Y[cnt]]); cnt++; ans.eb(mp(now[i], now[pos[s[i]]])); swap(s[i], s[pos[s[i]]]); } } while(ans.size() < m) ans.eb(mp(0, 0)); //cerr << "test " << m << "\n"; //printv(num, cerr); //printv(s, cerr); return true; } 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; bool tmp = calc(n, S, mid, X, Y); //cerr << mid << " " << tmp << "\n"; if(tmp) r = mid; else l = mid + 1; } //cerr << "ans " << l << "\n"; calc(n, S, l, X, Y); for(int i = 0; i < ans.size(); i++){ P[i] = ans[i].F; Q[i] = ans[i].Sc; } return ans.size(); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 1 ms | 204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 1 ms | 204 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 1 ms | 204 KB | Output is correct |
15 | Correct | 1 ms | 204 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 1 ms | 204 KB | Output is correct |
18 | Correct | 0 ms | 204 KB | Output is correct |
19 | Correct | 1 ms | 204 KB | Output is correct |
20 | Correct | 0 ms | 204 KB | Output is correct |
21 | Correct | 1 ms | 332 KB | Output is correct |
22 | Correct | 1 ms | 332 KB | Output is correct |
23 | Correct | 1 ms | 332 KB | Output is correct |
24 | Correct | 1 ms | 332 KB | Output is correct |
25 | Correct | 2 ms | 384 KB | Output is correct |
26 | Correct | 1 ms | 332 KB | Output is correct |
27 | Correct | 1 ms | 332 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 332 KB | Output is correct |
2 | Correct | 3 ms | 444 KB | Output is correct |
3 | Correct | 2 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 2 ms | 332 KB | Output is correct |
8 | Correct | 2 ms | 332 KB | Output is correct |
9 | Correct | 2 ms | 332 KB | Output is correct |
10 | Correct | 2 ms | 332 KB | Output is correct |
11 | Correct | 2 ms | 348 KB | Output is correct |
12 | Correct | 2 ms | 332 KB | Output is correct |
13 | Correct | 2 ms | 332 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 332 KB | Output is correct |
2 | Correct | 3 ms | 444 KB | Output is correct |
3 | Correct | 2 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 2 ms | 332 KB | Output is correct |
8 | Correct | 2 ms | 332 KB | Output is correct |
9 | Correct | 2 ms | 332 KB | Output is correct |
10 | Correct | 2 ms | 332 KB | Output is correct |
11 | Correct | 2 ms | 348 KB | Output is correct |
12 | Correct | 2 ms | 332 KB | Output is correct |
13 | Correct | 2 ms | 332 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
15 | Correct | 265 ms | 10912 KB | Output is correct |
16 | Correct | 301 ms | 18364 KB | Output is correct |
17 | Correct | 428 ms | 19160 KB | Output is correct |
18 | Correct | 100 ms | 17264 KB | Output is correct |
19 | Correct | 248 ms | 17832 KB | Output is correct |
20 | Correct | 338 ms | 18928 KB | Output is correct |
21 | Correct | 291 ms | 18916 KB | Output is correct |
22 | Correct | 263 ms | 15344 KB | Output is correct |
23 | Correct | 294 ms | 19484 KB | Output is correct |
24 | Correct | 404 ms | 19392 KB | Output is correct |
25 | Correct | 394 ms | 19480 KB | Output is correct |
26 | Correct | 257 ms | 17976 KB | Output is correct |
27 | Correct | 216 ms | 17836 KB | Output is correct |
28 | Correct | 386 ms | 18972 KB | Output is correct |
29 | Correct | 372 ms | 19268 KB | Output is correct |
30 | Correct | 171 ms | 17840 KB | Output is correct |
31 | Correct | 376 ms | 19332 KB | Output is correct |
32 | Correct | 299 ms | 18836 KB | Output is correct |
33 | Correct | 393 ms | 19456 KB | Output is correct |
34 | Correct | 325 ms | 19312 KB | Output is correct |
35 | Correct | 260 ms | 17600 KB | Output is correct |
36 | Correct | 89 ms | 17896 KB | Output is correct |
37 | Correct | 402 ms | 19712 KB | Output is correct |
38 | Correct | 413 ms | 19728 KB | Output is correct |
39 | Correct | 401 ms | 19124 KB | Output is correct |