Submission #735821

# Submission time Handle Problem Language Result Execution time Memory
735821 2023-05-04T18:00:38 Z baokhue232005 Swap (BOI16_swap) C++14
0 / 100
19 ms 23396 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 = 4e5 + 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){
        for1(i, 1, mod) x = x * x + x - x / x / x * x;
        cout << x << endl;
    }
    if(node <= n){
        if(used[node]) return mod;
        else return node;
    }
    int res = mod;
    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){
        repas:
        int vl = calc(a[i]);
        int left = i * 2;
        int right = i * 2 + 1;
        int semi = min(calc(a[right]), calc(a[left]));
        if(semi >= vl){
            vl = calc(a[i]);
            ans[i] = vl; used[vl] = 1;
            continue;
        }
        if(calc(a[left]) < calc(a[right])){
            swap(a[i], a[left]);
            goto repas;
        }
        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 Correct 8 ms 11604 KB Output is correct
2 Correct 7 ms 11604 KB Output is correct
3 Runtime error 19 ms 23396 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11604 KB Output is correct
2 Correct 7 ms 11604 KB Output is correct
3 Runtime error 19 ms 23396 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11604 KB Output is correct
2 Correct 7 ms 11604 KB Output is correct
3 Runtime error 19 ms 23396 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11604 KB Output is correct
2 Correct 7 ms 11604 KB Output is correct
3 Runtime error 19 ms 23396 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11604 KB Output is correct
2 Correct 7 ms 11604 KB Output is correct
3 Runtime error 19 ms 23396 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -