# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
810980 |
2023-08-06T18:52:39 Z |
Hakiers |
Swap (BOI16_swap) |
C++17 |
|
0 ms |
212 KB |
#include <iostream>
using namespace std;
const int MAXN = 5e5 + 7;
int t[MAXN];
int n;
void solve(int v){
int l = 2*v, r = 2*v + 1;
if(t[l] > t[v] && t[r] < t[v] && l <= n && r <= n){
if((t[2*l] > t[l] || 2*l > n) && (t[2*l + 1] > t[l] || 2*l + 1 > n)){
swap(t[v], t[l]);
swap(t[v], t[r]);
solve(l);
solve(r);
}
else{
if(l <= n){
if(t[v] > t[l]) swap(t[v], t[l]);
solve(l);
}
if(r <= n){
if(t[v] > t[r]) swap(t[v], t[r]);
solve(r);
}
}
}
else{
if(l <= n){
if(t[v] > t[l]) swap(t[v], t[l]);
solve(l);
}
if(r <= n){
if(t[v] > t[r]) swap(t[v], t[r]);
solve(r);
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++)
cin >> t[i];
solve(1);
for(int i = 1; i <= n; i++)
cout << t[i] << " ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |