# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
322181 | 2020-11-14T08:00:16 Z | dolphingarlic | Swap (BOI16_swap) | C++14 | 235 ms | 262144 KB |
#include <bits/stdc++.h> typedef long long ll; using namespace std; int n, a[1 << 18]; vector<int> dp[1 << 18][18][2]; vector<int> merge(int top, vector<int> &l, vector<int> &r) { vector<int> ret = {top}; for (int i = 0, j = 1; i < l.size(); i += j, j <<= 1) { for (int k = i; k < i + j; k++) ret.push_back(l[k]); for (int k = i; k < i + j; k++) ret.push_back(r[k]); } return ret; } void dfs(int node = 1, int level = 1) { if (node * 2 > n) { for (int i = 0; i < level; i++) for (int j : {0, 1}) { if (!(((node >> i + 1) << 1) + j)) continue; dp[node][i][j] = {a[((node >> i + 1) << 1) + j]}; } } else { dfs(node * 2, level + 1), dfs(node * 2 + 1, level + 1); for (int i = 0; i < level; i++) for (int j : {0, 1}) { if (!(((node >> i + 1) << 1) + j)) continue; int val = a[((node >> i + 1) << 1) + j]; int mn = min({val, a[2 * node], a[2 * node + 1]}); if (mn == val) { dp[node][i][j] = merge(val, dp[2 * node][0][0], dp[2 * node + 1][0][1]); } else if (mn == a[2 * node]) { dp[node][i][j] = merge(a[2 * node], dp[2 * node][i + 1][j], dp[2 * node + 1][0][1]); } else { dp[node][i][j] = min( merge(a[2 * node + 1], dp[2 * node][0][0], dp[2 * node + 1][i + 1][j]), merge(a[2 * node + 1], dp[2 * node][i + 1][j], dp[2 * node + 1][0][0]) ); } } } } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", a + i); int orig = n; while (__builtin_popcount(n + 1) != 1) a[++n] = n; dfs(); for (int i = 0; i < orig; i++) printf("%d ", dp[1][0][1][i]); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 133 ms | 221932 KB | Output is correct |
2 | Correct | 130 ms | 221932 KB | Output is correct |
3 | Correct | 130 ms | 222060 KB | Output is correct |
4 | Correct | 129 ms | 221932 KB | Output is correct |
5 | Correct | 131 ms | 221932 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 133 ms | 221932 KB | Output is correct |
2 | Correct | 130 ms | 221932 KB | Output is correct |
3 | Correct | 130 ms | 222060 KB | Output is correct |
4 | Correct | 129 ms | 221932 KB | Output is correct |
5 | Correct | 131 ms | 221932 KB | Output is correct |
6 | Correct | 132 ms | 221932 KB | Output is correct |
7 | Correct | 132 ms | 221996 KB | Output is correct |
8 | Correct | 133 ms | 221932 KB | Output is correct |
9 | Correct | 132 ms | 221932 KB | Output is correct |
10 | Correct | 130 ms | 221932 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 133 ms | 221932 KB | Output is correct |
2 | Correct | 130 ms | 221932 KB | Output is correct |
3 | Correct | 130 ms | 222060 KB | Output is correct |
4 | Correct | 129 ms | 221932 KB | Output is correct |
5 | Correct | 131 ms | 221932 KB | Output is correct |
6 | Correct | 132 ms | 221932 KB | Output is correct |
7 | Correct | 132 ms | 221996 KB | Output is correct |
8 | Correct | 133 ms | 221932 KB | Output is correct |
9 | Correct | 132 ms | 221932 KB | Output is correct |
10 | Correct | 130 ms | 221932 KB | Output is correct |
11 | Correct | 134 ms | 222700 KB | Output is correct |
12 | Correct | 143 ms | 222828 KB | Output is correct |
13 | Correct | 135 ms | 222700 KB | Output is correct |
14 | Correct | 134 ms | 222700 KB | Output is correct |
15 | Correct | 132 ms | 222700 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 133 ms | 221932 KB | Output is correct |
2 | Correct | 130 ms | 221932 KB | Output is correct |
3 | Correct | 130 ms | 222060 KB | Output is correct |
4 | Correct | 129 ms | 221932 KB | Output is correct |
5 | Correct | 131 ms | 221932 KB | Output is correct |
6 | Correct | 132 ms | 221932 KB | Output is correct |
7 | Correct | 132 ms | 221996 KB | Output is correct |
8 | Correct | 133 ms | 221932 KB | Output is correct |
9 | Correct | 132 ms | 221932 KB | Output is correct |
10 | Correct | 130 ms | 221932 KB | Output is correct |
11 | Correct | 134 ms | 222700 KB | Output is correct |
12 | Correct | 143 ms | 222828 KB | Output is correct |
13 | Correct | 135 ms | 222700 KB | Output is correct |
14 | Correct | 134 ms | 222700 KB | Output is correct |
15 | Correct | 132 ms | 222700 KB | Output is correct |
16 | Runtime error | 235 ms | 262144 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
17 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 133 ms | 221932 KB | Output is correct |
2 | Correct | 130 ms | 221932 KB | Output is correct |
3 | Correct | 130 ms | 222060 KB | Output is correct |
4 | Correct | 129 ms | 221932 KB | Output is correct |
5 | Correct | 131 ms | 221932 KB | Output is correct |
6 | Correct | 132 ms | 221932 KB | Output is correct |
7 | Correct | 132 ms | 221996 KB | Output is correct |
8 | Correct | 133 ms | 221932 KB | Output is correct |
9 | Correct | 132 ms | 221932 KB | Output is correct |
10 | Correct | 130 ms | 221932 KB | Output is correct |
11 | Correct | 134 ms | 222700 KB | Output is correct |
12 | Correct | 143 ms | 222828 KB | Output is correct |
13 | Correct | 135 ms | 222700 KB | Output is correct |
14 | Correct | 134 ms | 222700 KB | Output is correct |
15 | Correct | 132 ms | 222700 KB | Output is correct |
16 | Runtime error | 235 ms | 262144 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
17 | Halted | 0 ms | 0 KB | - |