Submission #534613

# Submission time Handle Problem Language Result Execution time Memory
534613 2022-03-08T11:48:45 Z tranxuanbach The Collection Game (BOI21_swaps) C++17
25 / 100
31 ms 516 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define endl '\n'
#define fi first
#define se second
#define For(i, l, r) for (auto i = (l); i < (r); i++)
#define ForE(i, l, r) for (auto i = (l); i <= (r); i++)
#define FordE(i, l, r) for (auto i = (l); i >= (r); i--)
#define Fora(v, a) for (auto v: (a))
#define bend(a) (a).begin(), (a).end()
#define isz(a) ((signed)(a).size())

using ll = long long;
using ld = long double;
using pii = pair <int, int>;
using vi = vector <int>;
using vpii = vector <pii>;
using vvi = vector <vi>;

#include "swaps.h"

const int N = 5e2 + 5;

int n;
vi vidx;

bool built = 0;

vpii vschedule; vector <bool> vstartschedule; vi vansschedule; int ctrschedule;

void compare(int i, int j, bool dir){
    if (!built){
        vschedule.emplace_back(i, j);
    }
    else{
        if (vstartschedule[ctrschedule]){
            schedule(vidx[vschedule[ctrschedule].fi], vidx[vschedule[ctrschedule].se]);
            int tctrschedule = ctrschedule + 1;
            while (tctrschedule < isz(vschedule) and !vstartschedule[tctrschedule]){
                schedule(vidx[vschedule[tctrschedule].fi], vidx[vschedule[tctrschedule].se]);
                tctrschedule++;
            }
            vi cac = visit();
            For(k, 0, isz(cac)){
                vansschedule[ctrschedule + k] = cac[k];
            }
        }
        if (dir == vansschedule[ctrschedule++]){
            swap(vidx[i], vidx[j]);
        }
    }
}

void bitonicmerge(int l, int n, bool dir){
    if (n == 1){
        return;
    }
    int m = 1;
    while (m * 2 < n){
        m *= 2;
    }
    For(i, l, l + n - m){
        compare(i, i + m, dir);
    }
    bitonicmerge(l, m, dir);
    bitonicmerge(l + m, n - m, dir);
}

void bitonicsort(int l, int n, bool dir){
    if (n == 1){
        return;
    }
    int m = n / 2;
    bitonicsort(l, m, !dir);
    bitonicsort(l + m, n - m, dir);
    bitonicmerge(l, n, dir);
}

void calschedule(){
    vstartschedule.assign(isz(vschedule), 0);
    vansschedule.assign(isz(vschedule), 0);
    int i = 0;
    while (i < isz(vschedule)){
        vstartschedule[i] = 1;
        set <int> stt;
        while (i < isz(vschedule)){
            if (stt.find(vschedule[i].fi) != stt.end() or stt.find(vschedule[i].se) != stt.end()){
                break;
            }
            stt.insert(vschedule[i].fi); stt.insert(vschedule[i].se);
            i++;
        }
    }
}

void solve(int _n, int v){
    n = _n;
    vidx.assign(n, 0);
    For(i, 0, n){
        vidx[i] = i + 1;
    }
    vschedule.clear(); vansschedule.clear(); ctrschedule = 0;

    built = 0;
    bitonicsort(0, n, 0);
    calschedule();
    built = 1;
    bitonicsort(0, n, 0);
    answer(vidx);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 5 ms 200 KB Correct
3 Correct 12 ms 328 KB Correct
4 Correct 27 ms 456 KB Correct
5 Correct 21 ms 508 KB Correct
6 Correct 23 ms 508 KB Correct
7 Correct 30 ms 516 KB Correct
8 Correct 23 ms 508 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 4 ms 200 KB Correct
3 Correct 12 ms 392 KB Correct
4 Correct 23 ms 456 KB Correct
5 Correct 30 ms 504 KB Correct
6 Correct 31 ms 456 KB Correct
7 Correct 30 ms 500 KB Correct
8 Correct 30 ms 456 KB Correct
9 Runtime error 14 ms 508 KB Execution killed with signal 13
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 4 ms 200 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 4 ms 200 KB Correct
3 Correct 1 ms 200 KB Correct
4 Correct 5 ms 200 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 6 ms 200 KB Correct
3 Correct 12 ms 372 KB Correct
4 Correct 26 ms 508 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 6 ms 200 KB Correct
3 Correct 12 ms 372 KB Correct
4 Correct 26 ms 508 KB Correct
5 Correct 1 ms 200 KB Correct
6 Correct 6 ms 200 KB Correct
7 Correct 10 ms 328 KB Correct
8 Correct 22 ms 504 KB Correct
9 Correct 27 ms 456 KB Correct
10 Correct 27 ms 504 KB Correct
11 Correct 28 ms 456 KB Correct
12 Correct 26 ms 456 KB Correct
13 Correct 1 ms 200 KB Correct
14 Correct 4 ms 200 KB Correct
15 Correct 7 ms 388 KB Correct
16 Correct 24 ms 500 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 6 ms 200 KB Correct
3 Correct 13 ms 328 KB Correct
4 Correct 19 ms 496 KB Correct
5 Runtime error 6 ms 456 KB Execution killed with signal 13
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 6 ms 200 KB Correct
3 Correct 13 ms 328 KB Correct
4 Correct 19 ms 496 KB Correct
5 Runtime error 6 ms 456 KB Execution killed with signal 13
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 4 ms 316 KB Correct
3 Correct 12 ms 328 KB Correct
4 Correct 27 ms 496 KB Correct
5 Runtime error 7 ms 416 KB Execution killed with signal 13
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 4 ms 316 KB Correct
3 Correct 12 ms 328 KB Correct
4 Correct 27 ms 496 KB Correct
5 Runtime error 7 ms 416 KB Execution killed with signal 13
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 4 ms 200 KB Correct
3 Correct 12 ms 368 KB Correct
4 Correct 30 ms 504 KB Correct
5 Runtime error 9 ms 400 KB Execution killed with signal 13
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 4 ms 200 KB Correct
3 Correct 12 ms 368 KB Correct
4 Correct 30 ms 504 KB Correct
5 Runtime error 9 ms 400 KB Execution killed with signal 13
6 Halted 0 ms 0 KB -