# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
813085 |
2023-08-07T13:20:10 Z |
Hakiers |
Swap (BOI16_swap) |
C++17 |
|
2 ms |
2260 KB |
#include <iostream>
using namespace std;
const int MAXN = 1 << 19;
const int oo = 1e9;
int t[MAXN];
int n;
bool check(int v, int val){
if(v > val) return true;
while(v < val/2)
val/=2;
if(val%2) return true;
return false;
}
void solve(int v){
if(v > n) return;
int l = 2*v, r = 2*v + 1;
if(t[v] < t[l] && t[v] < t[r]){
solve(l);
solve(r);
}
else if(t[l] < t[v] && t[v] < t[r]){
swap(t[v], t[l]);
solve(l);
solve(r);
}
else if(t[r] < t[l] && t[l] < t[v]){
swap(t[v], t[r]);
solve(l);
solve(r);
}
else if(t[r] < t[v] && t[v] < t[l]){
int tmp = t[l];
if(check(v, t[l])){
swap(t[v], t[l]);
swap(t[v], t[r]);
}
else
swap(t[v], t[r]);
solve(l);
solve(r);
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 1; i < MAXN; i++) t[i] = oo;
for(int i = 1; i <= n; i++)
cin >> t[i];
solve(1);
for(int i = 1; i <= n; i++)
cout << t[i] << " ";
}
Compilation message
swap.cpp: In function 'void solve(int)':
swap.cpp:40:13: warning: unused variable 'tmp' [-Wunused-variable]
40 | int tmp = t[l];
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |