Submission #813086

# Submission time Handle Problem Language Result Execution time Memory
813086 2023-08-07T13:20:42 Z Hakiers Swap (BOI16_swap) C++17
0 / 100
1 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]){
        
        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] << " ";
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2260 KB Output isn't correct
2 Halted 0 ms 0 KB -