# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
539009 |
2022-03-18T08:29:59 Z |
qwerasdfzxcl |
Swap (BOI16_swap) |
C++14 |
|
1000 ms |
178948 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> dp[200200][18][2];
int a[400400], n;
vector<int> combine(int x, int s1, int i1, int j1, int s2, int i2, int j2){
if (s1>n) return {x};
vector<int> ret = {x};
if (s2>n){
for (auto &y:dp[s1][i1][j1]) ret.push_back(y);
return ret;
}
int pt = 0;
for (int t=1;;t*=2){
for (int i=0;i<t;i++){
if (pt+i>=(int)dp[s1][i1][j1].size()) break;
ret.push_back(dp[s1][i1][j1][pt+i]);
}
for (int i=0;i<t;i++){
if (pt+i>=(int)dp[s2][i2][j2].size()) break;
ret.push_back(dp[s2][i2][j2][pt+i]);
}
pt += t;
if (pt>=(int)dp[s1][i1][j1].size() && pt>=(int)dp[s2][i2][j2].size()) break;
}
return ret;
}
void _delete(int s){
if (s>n) return;
for (int i=0;i<20;i++){
dp[s][i][0].clear();
dp[s][i][1].clear();
dp[s][i][0].shrink_to_fit();
dp[s][i][1].shrink_to_fit();
}
}
void dfs(int s, int dep, vector<pair<int, int>> C){
C.emplace_back(dep+1, 0);
if (s*2<=n){
dfs(s*2, dep+1, C);
}
if (s*2+1<=n){
C.pop_back();
C.emplace_back(dep, 1);
C.emplace_back(dep+1, 0);
dfs(s*2+1, dep+1, C);
C.pop_back();
}
C.pop_back();
reverse(C.begin(), C.end());
int cur = s, cdep = dep;
for (auto &[i, j]:C){
while(cdep>i){
cdep--; cur /= 2;
}
assert(cdep==i);
if (j==1) cur *= 2;
int mn = min({a[cur], a[s*2], a[s*2+1]});
if (mn==a[cur]) dp[s][i][j] = combine(a[cur], s*2, dep+1, 0, s*2+1, dep+1, 0);
else if (mn==a[s*2]) dp[s][i][j] = combine(a[s*2], s*2, i, j, s*2+1, dep+1, 0);
else{
dp[s][i][j] = min(combine(a[s*2+1], s*2, dep+1, 0, s*2+1, i, j), combine(a[s*2+1], s*2, i, j, s*2+1, dep, 1));
}
if (j==1) cur /= 2;
}
_delete(s*2);
_delete(s*2+1);
}
int main(){
scanf("%d", &n);
for (int i=1;i<=n;i++) scanf("%d", a+i);
for (int i=n+1;i<=n*2+1;i++) a[i] = 1e9;
dfs(1, 1, {{1, 0}});
for (auto &x:dp[1][1][0]) printf("%d ", x);
return 0;
}
Compilation message
swap.cpp: In function 'void dfs(int, int, std::vector<std::pair<int, int> >)':
swap.cpp:60:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
60 | for (auto &[i, j]:C){
| ^
swap.cpp: In function 'int main()':
swap.cpp:82:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
82 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
swap.cpp:83:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
83 | for (int i=1;i<=n;i++) scanf("%d", a+i);
| ~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
169540 KB |
Output is correct |
2 |
Correct |
81 ms |
169548 KB |
Output is correct |
3 |
Correct |
86 ms |
169540 KB |
Output is correct |
4 |
Correct |
90 ms |
169548 KB |
Output is correct |
5 |
Correct |
93 ms |
169492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
169540 KB |
Output is correct |
2 |
Correct |
81 ms |
169548 KB |
Output is correct |
3 |
Correct |
86 ms |
169540 KB |
Output is correct |
4 |
Correct |
90 ms |
169548 KB |
Output is correct |
5 |
Correct |
93 ms |
169492 KB |
Output is correct |
6 |
Correct |
94 ms |
169504 KB |
Output is correct |
7 |
Correct |
83 ms |
169524 KB |
Output is correct |
8 |
Correct |
90 ms |
169612 KB |
Output is correct |
9 |
Correct |
87 ms |
169560 KB |
Output is correct |
10 |
Correct |
90 ms |
169516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
169540 KB |
Output is correct |
2 |
Correct |
81 ms |
169548 KB |
Output is correct |
3 |
Correct |
86 ms |
169540 KB |
Output is correct |
4 |
Correct |
90 ms |
169548 KB |
Output is correct |
5 |
Correct |
93 ms |
169492 KB |
Output is correct |
6 |
Correct |
94 ms |
169504 KB |
Output is correct |
7 |
Correct |
83 ms |
169524 KB |
Output is correct |
8 |
Correct |
90 ms |
169612 KB |
Output is correct |
9 |
Correct |
87 ms |
169560 KB |
Output is correct |
10 |
Correct |
90 ms |
169516 KB |
Output is correct |
11 |
Correct |
92 ms |
169604 KB |
Output is correct |
12 |
Correct |
97 ms |
169512 KB |
Output is correct |
13 |
Correct |
89 ms |
169568 KB |
Output is correct |
14 |
Correct |
105 ms |
169516 KB |
Output is correct |
15 |
Correct |
106 ms |
169584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
169540 KB |
Output is correct |
2 |
Correct |
81 ms |
169548 KB |
Output is correct |
3 |
Correct |
86 ms |
169540 KB |
Output is correct |
4 |
Correct |
90 ms |
169548 KB |
Output is correct |
5 |
Correct |
93 ms |
169492 KB |
Output is correct |
6 |
Correct |
94 ms |
169504 KB |
Output is correct |
7 |
Correct |
83 ms |
169524 KB |
Output is correct |
8 |
Correct |
90 ms |
169612 KB |
Output is correct |
9 |
Correct |
87 ms |
169560 KB |
Output is correct |
10 |
Correct |
90 ms |
169516 KB |
Output is correct |
11 |
Correct |
92 ms |
169604 KB |
Output is correct |
12 |
Correct |
97 ms |
169512 KB |
Output is correct |
13 |
Correct |
89 ms |
169568 KB |
Output is correct |
14 |
Correct |
105 ms |
169516 KB |
Output is correct |
15 |
Correct |
106 ms |
169584 KB |
Output is correct |
16 |
Correct |
251 ms |
171696 KB |
Output is correct |
17 |
Correct |
277 ms |
171428 KB |
Output is correct |
18 |
Correct |
246 ms |
171720 KB |
Output is correct |
19 |
Correct |
349 ms |
171772 KB |
Output is correct |
20 |
Correct |
299 ms |
171836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
169540 KB |
Output is correct |
2 |
Correct |
81 ms |
169548 KB |
Output is correct |
3 |
Correct |
86 ms |
169540 KB |
Output is correct |
4 |
Correct |
90 ms |
169548 KB |
Output is correct |
5 |
Correct |
93 ms |
169492 KB |
Output is correct |
6 |
Correct |
94 ms |
169504 KB |
Output is correct |
7 |
Correct |
83 ms |
169524 KB |
Output is correct |
8 |
Correct |
90 ms |
169612 KB |
Output is correct |
9 |
Correct |
87 ms |
169560 KB |
Output is correct |
10 |
Correct |
90 ms |
169516 KB |
Output is correct |
11 |
Correct |
92 ms |
169604 KB |
Output is correct |
12 |
Correct |
97 ms |
169512 KB |
Output is correct |
13 |
Correct |
89 ms |
169568 KB |
Output is correct |
14 |
Correct |
105 ms |
169516 KB |
Output is correct |
15 |
Correct |
106 ms |
169584 KB |
Output is correct |
16 |
Correct |
251 ms |
171696 KB |
Output is correct |
17 |
Correct |
277 ms |
171428 KB |
Output is correct |
18 |
Correct |
246 ms |
171720 KB |
Output is correct |
19 |
Correct |
349 ms |
171772 KB |
Output is correct |
20 |
Correct |
299 ms |
171836 KB |
Output is correct |
21 |
Correct |
928 ms |
178224 KB |
Output is correct |
22 |
Correct |
856 ms |
178004 KB |
Output is correct |
23 |
Correct |
835 ms |
177520 KB |
Output is correct |
24 |
Execution timed out |
1063 ms |
178948 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |