# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
322234 | 2020-11-14T10:08:01 Z | dolphingarlic | Swap (BOI16_swap) | C++14 | 408 ms | 262148 KB |
#include <bits/stdc++.h> using namespace std; int a[200002]; vector<int> dp[200002][18][2], tmp; void merge(vector<int> &ret, vector<int> &l, vector<int> &r) { for (int i = 0, j = 1; i < l.size(); i += j, j <<= 1) { for (int k = i; k < i + j && k < l.size(); k++) ret.push_back(l[k]); for (int k = i; k < i + j && k < r.size(); k++) ret.push_back(r[k]); } } int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", a + i); for (int node = n; node; node--) { for (int i = 0; node >> i; i++) for (int j : {0, 1}) { if (!(((node >> i + 1) << 1) + j)) continue; int val = a[((node >> i + 1) << 1) + j]; if (node * 2 > n) dp[node][i][j] = {val}; else if (node * 2 + 1 > n) { if (val < a[2 * node]) dp[node][i][j] = {val, a[2 * node]}; else dp[node][i][j] = {a[2 * node], val}; } else { int mn = min({val, a[2 * node], a[2 * node + 1]}); if (mn == val) { dp[node][i][j] = {val}; merge(dp[node][i][j], dp[2 * node][0][0], dp[2 * node + 1][0][1]); } else if (mn == a[2 * node]) { dp[node][i][j] = {a[2 * node]}; merge(dp[node][i][j], dp[2 * node][i + 1][j], dp[2 * node + 1][0][1]); } else { dp[node][i][j] = tmp = {a[2 * node + 1]}; merge(dp[node][i][j], dp[2 * node][0][0], dp[2 * node + 1][i + 1][j]); merge(tmp, dp[2 * node][i + 1][j], dp[2 * node + 1][0][0]); dp[node][i][j] = min(dp[node][i][j], tmp); } vector<int>().swap(dp[2 * node][i + 1][j]); vector<int>().swap(dp[2 * node + 1][i + 1][j]); } } if (node * 2 <= n) { vector<int>().swap(dp[node * 2][0][0]); vector<int>().swap(dp[node * 2][0][1]); vector<int>().swap(dp[node * 2 + 1][0][0]); vector<int>().swap(dp[node * 2 + 1][0][1]); } } for (int i : dp[1][0][1]) printf("%d ", i); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 115 ms | 169452 KB | Output is correct |
2 | Correct | 104 ms | 169452 KB | Output is correct |
3 | Correct | 102 ms | 169452 KB | Output is correct |
4 | Correct | 100 ms | 169452 KB | Output is correct |
5 | Correct | 100 ms | 169372 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 115 ms | 169452 KB | Output is correct |
2 | Correct | 104 ms | 169452 KB | Output is correct |
3 | Correct | 102 ms | 169452 KB | Output is correct |
4 | Correct | 100 ms | 169452 KB | Output is correct |
5 | Correct | 100 ms | 169372 KB | Output is correct |
6 | Correct | 101 ms | 169452 KB | Output is correct |
7 | Correct | 102 ms | 169452 KB | Output is correct |
8 | Correct | 102 ms | 169452 KB | Output is correct |
9 | Correct | 108 ms | 169452 KB | Output is correct |
10 | Correct | 103 ms | 169452 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 115 ms | 169452 KB | Output is correct |
2 | Correct | 104 ms | 169452 KB | Output is correct |
3 | Correct | 102 ms | 169452 KB | Output is correct |
4 | Correct | 100 ms | 169452 KB | Output is correct |
5 | Correct | 100 ms | 169372 KB | Output is correct |
6 | Correct | 101 ms | 169452 KB | Output is correct |
7 | Correct | 102 ms | 169452 KB | Output is correct |
8 | Correct | 102 ms | 169452 KB | Output is correct |
9 | Correct | 108 ms | 169452 KB | Output is correct |
10 | Correct | 103 ms | 169452 KB | Output is correct |
11 | Correct | 103 ms | 169708 KB | Output is correct |
12 | Correct | 106 ms | 169708 KB | Output is correct |
13 | Correct | 107 ms | 169708 KB | Output is correct |
14 | Correct | 109 ms | 169708 KB | Output is correct |
15 | Correct | 105 ms | 169708 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 115 ms | 169452 KB | Output is correct |
2 | Correct | 104 ms | 169452 KB | Output is correct |
3 | Correct | 102 ms | 169452 KB | Output is correct |
4 | Correct | 100 ms | 169452 KB | Output is correct |
5 | Correct | 100 ms | 169372 KB | Output is correct |
6 | Correct | 101 ms | 169452 KB | Output is correct |
7 | Correct | 102 ms | 169452 KB | Output is correct |
8 | Correct | 102 ms | 169452 KB | Output is correct |
9 | Correct | 108 ms | 169452 KB | Output is correct |
10 | Correct | 103 ms | 169452 KB | Output is correct |
11 | Correct | 103 ms | 169708 KB | Output is correct |
12 | Correct | 106 ms | 169708 KB | Output is correct |
13 | Correct | 107 ms | 169708 KB | Output is correct |
14 | Correct | 109 ms | 169708 KB | Output is correct |
15 | Correct | 105 ms | 169708 KB | Output is correct |
16 | Correct | 362 ms | 193788 KB | Output is correct |
17 | Correct | 363 ms | 193820 KB | Output is correct |
18 | Correct | 369 ms | 193772 KB | Output is correct |
19 | Correct | 406 ms | 193900 KB | Output is correct |
20 | Correct | 408 ms | 193888 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 115 ms | 169452 KB | Output is correct |
2 | Correct | 104 ms | 169452 KB | Output is correct |
3 | Correct | 102 ms | 169452 KB | Output is correct |
4 | Correct | 100 ms | 169452 KB | Output is correct |
5 | Correct | 100 ms | 169372 KB | Output is correct |
6 | Correct | 101 ms | 169452 KB | Output is correct |
7 | Correct | 102 ms | 169452 KB | Output is correct |
8 | Correct | 102 ms | 169452 KB | Output is correct |
9 | Correct | 108 ms | 169452 KB | Output is correct |
10 | Correct | 103 ms | 169452 KB | Output is correct |
11 | Correct | 103 ms | 169708 KB | Output is correct |
12 | Correct | 106 ms | 169708 KB | Output is correct |
13 | Correct | 107 ms | 169708 KB | Output is correct |
14 | Correct | 109 ms | 169708 KB | Output is correct |
15 | Correct | 105 ms | 169708 KB | Output is correct |
16 | Correct | 362 ms | 193788 KB | Output is correct |
17 | Correct | 363 ms | 193820 KB | Output is correct |
18 | Correct | 369 ms | 193772 KB | Output is correct |
19 | Correct | 406 ms | 193900 KB | Output is correct |
20 | Correct | 408 ms | 193888 KB | Output is correct |
21 | Runtime error | 299 ms | 262148 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
22 | Halted | 0 ms | 0 KB | - |