Submission #735826

# Submission time Handle Problem Language Result Execution time Memory
735826 2023-05-04T18:12:40 Z baokhue232005 Swap (BOI16_swap) C++14
0 / 100
15 ms 28628 KB
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
// lethal option

#include<bits/stdc++.h>
using namespace std;

#define all(flg) flg.begin(), flg.end()
#define pb push_back
#define fi first
#define se second
#define eb emplace_back
#define ii pair<int, int>
#define vi vector<int>
#define PI 3.141592653589793238462643383279502884
#define ll long long
#define ld long double
#define for1(i, ff, gg) for(int i = ff; i <= gg; ++i)
#define for2(i, ff, gg) for(int i = ff; i >= gg; --i)
const int mod = 1e9 + 7;
const int maxN = 1e6 + 5;
int n, a[maxN];
int x, y, z, k;


int cnt = n;
vi vc[maxN];

bool used[maxN];
int calc(int node, int dep = 0){
    if(dep > 100) exit(0);
    if(node <= n){
        if(used[node]) return mod;
        else return node;
    }
    int res = mod;
    if(vc[node].size() > 2) exit(0);
    for(int cc : vc[node]){
        int val = calc(cc, dep + 1);
        res = min(res, val);
    }
    return res;
}

int ans[maxN];

signed main(){
    // freopen(".inp", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    memset(used, 0, sizeof(used));
    memset(a, 0, sizeof(a));
    for1(i, 1, n) cin >> a[i];
    cnt = n;
    used[0] = 1;
    for1(i, 1, n){
        int vl = calc(a[i]);
        int left = i * 2;
        int right = i * 2 + 1;
        int semi = min(a[right], a[left]);
        if(semi >= vl){
            ans[i] = vl; used[vl] = 1;
            continue;
        }
        if(a[left] < a[right]){
            swap(a[i], a[left]);
            vl = a[i];
            ans[i] = vl; used[vl] = 1;
            continue;
        }
        int node = ++cnt;
        vc[node].pb(a[left]);
        vc[node].pb(a[i]);
        ans[i] = a[right];
        used[a[right]] = 1;
        a[left] = node;
        a[right] = node;
    }
    for1(i, 1, n) cout << ans[i] << " ";
    cout << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 28628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 28628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 28628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 28628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 28628 KB Output isn't correct
2 Halted 0 ms 0 KB -