# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
27112 |
2017-07-09T09:55:08 Z |
김동현(#1117) |
Swap (BOI16_swap) |
C++14 |
|
1000 ms |
212056 KB |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
int n, sz, a[262144], av[262144], bv[262144], ans[262144];
unordered_map<int, int> num[262144];
vector<int> v, lv, rv;
queue<int> q;
void mrg(int *ar, int a, int b){
int c = 0;
if(~a) q.push(a); if(~b) q.push(b);
while(!q.empty()){
int x = q.front(); q.pop();
ar[c++] = v[x];
if(~lv[x]) q.push(lv[x]);
if(~rv[x]) q.push(rv[x]);
}
}
int f(int x, int r){
if(num[x].find(r) != num[x].end()) return num[x][r];
if(x > sz / 2){
v.push_back(r);
lv.push_back(-1);
rv.push_back(-1);
}
else{
int t[3] = {r, a[2 * x], a[2 * x + 1]};
sort(t, t + 3);
if(t[0] != a[2 * x + 1]){
int lt = f(2 * x, r + a[2 * x] - t[0]), rt = f(2 * x + 1, a[2 * x + 1]);
v.push_back(t[0]);
lv.push_back(lt);
rv.push_back(rt);
}
else{
int al = f(2 * x, r), ar = f(2 * x + 1, a[2 * x]);
int bl = f(2 * x, a[2 * x]), br = f(2 * x + 1, r);
mrg(av, al, ar);
mrg(bv, bl, br);
for(int i = 0; ; i++){
if(av[i] != bv[i]){
v.push_back(t[0]);
if(av[i] < bv[i]){
lv.push_back(al);
rv.push_back(ar);
}
else{
lv.push_back(bl);
rv.push_back(br);
}
break;
}
}
}
}
num[x][r] = int(v.size()) - 1;
return int(v.size()) - 1;
}
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d", a + i);
for(sz = 1; sz < n; sz = 2 * sz + 1);
for(int i = n + 1; i <= sz; i++) a[i] = i;
mrg(ans, f(1, a[1]), -1);
for(int i = 0; i < n; i++) printf("%d ", ans[i]);
puts("");
}
Compilation message
swap.cpp: In function 'int main()':
swap.cpp:63:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
swap.cpp:64:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i = 1; i <= n; i++) scanf("%d", a + i);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
20464 KB |
Output is correct |
2 |
Correct |
6 ms |
20464 KB |
Output is correct |
3 |
Correct |
3 ms |
20464 KB |
Output is correct |
4 |
Correct |
6 ms |
20464 KB |
Output is correct |
5 |
Correct |
6 ms |
20464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
20464 KB |
Output is correct |
2 |
Correct |
6 ms |
20464 KB |
Output is correct |
3 |
Correct |
3 ms |
20464 KB |
Output is correct |
4 |
Correct |
6 ms |
20464 KB |
Output is correct |
5 |
Correct |
6 ms |
20464 KB |
Output is correct |
6 |
Correct |
3 ms |
20464 KB |
Output is correct |
7 |
Correct |
3 ms |
20464 KB |
Output is correct |
8 |
Correct |
3 ms |
20464 KB |
Output is correct |
9 |
Correct |
3 ms |
20464 KB |
Output is correct |
10 |
Correct |
0 ms |
20464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
20464 KB |
Output is correct |
2 |
Correct |
6 ms |
20464 KB |
Output is correct |
3 |
Correct |
3 ms |
20464 KB |
Output is correct |
4 |
Correct |
6 ms |
20464 KB |
Output is correct |
5 |
Correct |
6 ms |
20464 KB |
Output is correct |
6 |
Correct |
3 ms |
20464 KB |
Output is correct |
7 |
Correct |
3 ms |
20464 KB |
Output is correct |
8 |
Correct |
3 ms |
20464 KB |
Output is correct |
9 |
Correct |
3 ms |
20464 KB |
Output is correct |
10 |
Correct |
0 ms |
20464 KB |
Output is correct |
11 |
Correct |
6 ms |
20596 KB |
Output is correct |
12 |
Correct |
6 ms |
20728 KB |
Output is correct |
13 |
Correct |
3 ms |
20596 KB |
Output is correct |
14 |
Correct |
3 ms |
20992 KB |
Output is correct |
15 |
Correct |
6 ms |
20988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
20464 KB |
Output is correct |
2 |
Correct |
6 ms |
20464 KB |
Output is correct |
3 |
Correct |
3 ms |
20464 KB |
Output is correct |
4 |
Correct |
6 ms |
20464 KB |
Output is correct |
5 |
Correct |
6 ms |
20464 KB |
Output is correct |
6 |
Correct |
3 ms |
20464 KB |
Output is correct |
7 |
Correct |
3 ms |
20464 KB |
Output is correct |
8 |
Correct |
3 ms |
20464 KB |
Output is correct |
9 |
Correct |
3 ms |
20464 KB |
Output is correct |
10 |
Correct |
0 ms |
20464 KB |
Output is correct |
11 |
Correct |
6 ms |
20596 KB |
Output is correct |
12 |
Correct |
6 ms |
20728 KB |
Output is correct |
13 |
Correct |
3 ms |
20596 KB |
Output is correct |
14 |
Correct |
3 ms |
20992 KB |
Output is correct |
15 |
Correct |
6 ms |
20988 KB |
Output is correct |
16 |
Correct |
56 ms |
30984 KB |
Output is correct |
17 |
Correct |
56 ms |
30856 KB |
Output is correct |
18 |
Correct |
56 ms |
30852 KB |
Output is correct |
19 |
Correct |
333 ms |
65756 KB |
Output is correct |
20 |
Correct |
493 ms |
65620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
20464 KB |
Output is correct |
2 |
Correct |
6 ms |
20464 KB |
Output is correct |
3 |
Correct |
3 ms |
20464 KB |
Output is correct |
4 |
Correct |
6 ms |
20464 KB |
Output is correct |
5 |
Correct |
6 ms |
20464 KB |
Output is correct |
6 |
Correct |
3 ms |
20464 KB |
Output is correct |
7 |
Correct |
3 ms |
20464 KB |
Output is correct |
8 |
Correct |
3 ms |
20464 KB |
Output is correct |
9 |
Correct |
3 ms |
20464 KB |
Output is correct |
10 |
Correct |
0 ms |
20464 KB |
Output is correct |
11 |
Correct |
6 ms |
20596 KB |
Output is correct |
12 |
Correct |
6 ms |
20728 KB |
Output is correct |
13 |
Correct |
3 ms |
20596 KB |
Output is correct |
14 |
Correct |
3 ms |
20992 KB |
Output is correct |
15 |
Correct |
6 ms |
20988 KB |
Output is correct |
16 |
Correct |
56 ms |
30984 KB |
Output is correct |
17 |
Correct |
56 ms |
30856 KB |
Output is correct |
18 |
Correct |
56 ms |
30852 KB |
Output is correct |
19 |
Correct |
333 ms |
65756 KB |
Output is correct |
20 |
Correct |
493 ms |
65620 KB |
Output is correct |
21 |
Correct |
299 ms |
62064 KB |
Output is correct |
22 |
Correct |
276 ms |
62072 KB |
Output is correct |
23 |
Correct |
293 ms |
62068 KB |
Output is correct |
24 |
Execution timed out |
1000 ms |
212056 KB |
Execution timed out |
25 |
Halted |
0 ms |
0 KB |
- |