Submission #940202

# Submission time Handle Problem Language Result Execution time Memory
940202 2024-03-07T06:35:34 Z Darren0724 Swap (BOI16_swap) C++17
0 / 100
1 ms 1116 KB
#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=200005;
const int INF=1e9;
int n;
vector<int> v(N);
int mn(int i){
    int a=i*2,b=i*2+1;
    if(a>n)return v[i];
    if(b>n)return min(v[a],v[i]);
    return min({v[a],v[b],v[i]});
}
int32_t main() {
    LCBorz;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>v[i];
    }
    for(int i=1;i<=n;i++){
        int a=i*2,b=i*2+1;
        if(a>n)break;
        if(b>n){
            if(v[a]<v[i])swap(v[a],v[i]);
            break;
        }
        int id=0;
        vector<int> c={v[i],mn(a),mn(b)};
        for(int mask=1;mask<4;mask++){
            if(mask&1)swap(v[i],v[a]);
            if(mask&2)swap(v[i],v[b]);
            vector<int> d={v[i],mn(a),mn(b)};
            if(mask&2)swap(v[i],v[b]);
            if(mask&1)swap(v[i],v[a]);
            if(c>d){
                id=mask;
                c=d;
            }
        }
        if(id&1)swap(v[i],v[a]);
        if(id&2)swap(v[i],v[b]);
    }
    for(int i=1;i<=n;i++){
        cout<<v[i]<<' ';
    }
    cout<<endl;
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -