# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
703025 |
2023-02-25T16:01:56 Z |
406 |
Swap (BOI16_swap) |
C++17 |
|
1000 ms |
42988 KB |
#include "bits/stdc++.h"
using namespace std;
#define int long long
const int N = 2e5 + 5;
const int L = 20;
const long long INF = 1ll << 60;
unordered_map<int, vector<int>> dp[N];
int n, a[4 * N];
void merge(vector<int> &a, const vector<int> b, const vector<int> c) {
assert(b.size() && c.size());
assert(b.size() == c.size());
int ptr = 0;
for (int i = 0; ptr < b.size(); i++) {
for (int j = 0; j < (1 << i); j++) {
a.push_back(b[j + ptr]);
}
for (int j = 0; j < (1 << i); j++) {
a.push_back(c[j + ptr]);
}
ptr += 1 << i;
}
}
void DP(int i, int j) {
if (i >= n / 2) {
dp[i][j] = {j};
return;
}
int r = a[2 * i + 1];
int l = a[2 * i];
if (j <= l && j <= r) {
DP(i * 2, l);
DP(i * 2 + 1, r);
vector<int> re{j};
merge(re, dp[i << 1][l], dp[i << 1 | 1][r]);
dp[i][j] = re;
return;
}
if (j <= l) {
DP(i * 2, j);
DP(i * 2 + 1, j);
DP(i * 2, l);
DP(i * 2 + 1, l);
vector<int> re{r};
merge(re, dp[i * 2][l], dp[i * 2 + 1][j]);
vector<int> re2{r};
merge(re2, dp[i * 2][j], dp[i * 2 + 1][l]);
dp[i][j] = min(re, re2);
return;
}
if (j <= r) {
DP(i * 2, j);
DP(i * 2 + 1, r);
vector<int> re{l};
merge(re, dp[i << 1][j], dp[i << 1 | 1][r]);
dp[i][j] = re;
return;
}
if (r < l) {
DP(i * 2, l);
DP(i * 2 + 1, j);
DP(i * 2, j);
DP(i * 2 + 1, l);
vector<int> re{r};
merge(re, dp[i * 2][l], dp[i * 2 + 1][j]);
vector<int> re2{r};
merge(re2, dp[i * 2][j], dp[i * 2 + 1][l]);
dp[i][j] = min(re, re2);
}
else {
DP(i * 2 + 1, r);
DP(i * 2, j);
vector<int> re{l};
merge(re, dp[i * 2][j], dp[i * 2 + 1][r]);
dp[i][j] = re;
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
while (n & (n - 1)) {
a[++n] = INF;
}
DP(1, a[1]);
for (auto u: dp[1][a[1]]) if (u != INF)
cout << u << ' ';
cout << '\n';
return 0;
}
Compilation message
swap.cpp: In function 'void merge(std::vector<long long int>&, std::vector<long long int>, std::vector<long long int>)':
swap.cpp:14:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for (int i = 0; ptr < b.size(); i++) {
| ~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11220 KB |
Output is correct |
2 |
Correct |
6 ms |
11220 KB |
Output is correct |
3 |
Correct |
6 ms |
11220 KB |
Output is correct |
4 |
Correct |
6 ms |
11220 KB |
Output is correct |
5 |
Correct |
6 ms |
11236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11220 KB |
Output is correct |
2 |
Correct |
6 ms |
11220 KB |
Output is correct |
3 |
Correct |
6 ms |
11220 KB |
Output is correct |
4 |
Correct |
6 ms |
11220 KB |
Output is correct |
5 |
Correct |
6 ms |
11236 KB |
Output is correct |
6 |
Correct |
6 ms |
11220 KB |
Output is correct |
7 |
Correct |
6 ms |
11220 KB |
Output is correct |
8 |
Correct |
6 ms |
11220 KB |
Output is correct |
9 |
Correct |
6 ms |
11220 KB |
Output is correct |
10 |
Correct |
8 ms |
11220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11220 KB |
Output is correct |
2 |
Correct |
6 ms |
11220 KB |
Output is correct |
3 |
Correct |
6 ms |
11220 KB |
Output is correct |
4 |
Correct |
6 ms |
11220 KB |
Output is correct |
5 |
Correct |
6 ms |
11236 KB |
Output is correct |
6 |
Correct |
6 ms |
11220 KB |
Output is correct |
7 |
Correct |
6 ms |
11220 KB |
Output is correct |
8 |
Correct |
6 ms |
11220 KB |
Output is correct |
9 |
Correct |
6 ms |
11220 KB |
Output is correct |
10 |
Correct |
8 ms |
11220 KB |
Output is correct |
11 |
Correct |
9 ms |
11696 KB |
Output is correct |
12 |
Correct |
13 ms |
11732 KB |
Output is correct |
13 |
Correct |
8 ms |
11604 KB |
Output is correct |
14 |
Correct |
38 ms |
12224 KB |
Output is correct |
15 |
Correct |
42 ms |
12252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11220 KB |
Output is correct |
2 |
Correct |
6 ms |
11220 KB |
Output is correct |
3 |
Correct |
6 ms |
11220 KB |
Output is correct |
4 |
Correct |
6 ms |
11220 KB |
Output is correct |
5 |
Correct |
6 ms |
11236 KB |
Output is correct |
6 |
Correct |
6 ms |
11220 KB |
Output is correct |
7 |
Correct |
6 ms |
11220 KB |
Output is correct |
8 |
Correct |
6 ms |
11220 KB |
Output is correct |
9 |
Correct |
6 ms |
11220 KB |
Output is correct |
10 |
Correct |
8 ms |
11220 KB |
Output is correct |
11 |
Correct |
9 ms |
11696 KB |
Output is correct |
12 |
Correct |
13 ms |
11732 KB |
Output is correct |
13 |
Correct |
8 ms |
11604 KB |
Output is correct |
14 |
Correct |
38 ms |
12224 KB |
Output is correct |
15 |
Correct |
42 ms |
12252 KB |
Output is correct |
16 |
Correct |
713 ms |
42988 KB |
Output is correct |
17 |
Correct |
414 ms |
41596 KB |
Output is correct |
18 |
Correct |
557 ms |
42500 KB |
Output is correct |
19 |
Execution timed out |
1061 ms |
22360 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11220 KB |
Output is correct |
2 |
Correct |
6 ms |
11220 KB |
Output is correct |
3 |
Correct |
6 ms |
11220 KB |
Output is correct |
4 |
Correct |
6 ms |
11220 KB |
Output is correct |
5 |
Correct |
6 ms |
11236 KB |
Output is correct |
6 |
Correct |
6 ms |
11220 KB |
Output is correct |
7 |
Correct |
6 ms |
11220 KB |
Output is correct |
8 |
Correct |
6 ms |
11220 KB |
Output is correct |
9 |
Correct |
6 ms |
11220 KB |
Output is correct |
10 |
Correct |
8 ms |
11220 KB |
Output is correct |
11 |
Correct |
9 ms |
11696 KB |
Output is correct |
12 |
Correct |
13 ms |
11732 KB |
Output is correct |
13 |
Correct |
8 ms |
11604 KB |
Output is correct |
14 |
Correct |
38 ms |
12224 KB |
Output is correct |
15 |
Correct |
42 ms |
12252 KB |
Output is correct |
16 |
Correct |
713 ms |
42988 KB |
Output is correct |
17 |
Correct |
414 ms |
41596 KB |
Output is correct |
18 |
Correct |
557 ms |
42500 KB |
Output is correct |
19 |
Execution timed out |
1061 ms |
22360 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |