Submission #735818

# Submission time Handle Problem Language Result Execution time Memory
735818 2023-05-04T17:51:16 Z baokhue232005 Swap (BOI16_swap) C++14
0 / 100
7 ms 10068 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, bool fucked = 0){
    if(node <= n){
        assert(node > 0);
        if(used[node]) return mod;
        else return node;
    }
    int res = mod;
    for(int cc : vc[node]){
        int val = calc(cc, fucked);
        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;
    for1(i, 1, n) cin >> a[i];
    cnt = n;
    memset(used, 0, sizeof(used));
    for1(i, 1, n){
        repas:
        // for1(j, i, n) cout << a[j] << " ";
        // cout << endl;
        int vl = calc(a[i]);
        int semi = mod;
        int left = i * 2;
        int right = i * 2 + 1;
        if(left <= n) semi = min(semi, calc(a[left]));
        if(right <= n) semi = min(semi, calc(a[right]));
        if(semi >= vl){
            ans[i] = vl; used[vl] = 1;
            // calc(a[i], 1);
            // exit(0);
            // cout << "cow: " << i << " " << calc(a[i]) << " " << a[i] << endl;
            continue;
        }
        if(calc(a[left]) < vl){
            swap(a[left], a[i]);
            goto repas;
        }
        if(right <= n){
            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;
}

Compilation message

swap.cpp: In function 'int main()':
swap.cpp:50:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |     freopen(".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 10068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 10068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 10068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 10068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 10068 KB Output isn't correct
2 Halted 0 ms 0 KB -