답안 #1024286

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1024286 2024-07-15T23:10:07 Z efishel 자동 인형 (IOI18_doll) C++17
100 / 100
117 ms 39476 KB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using vi = vector <int>;

struct Switch {
    Switch *x, *y;
    bool pointX;
    ll id;
    ll in, act;
    bool isEnd;
    bool isAct;

    Switch (ll in, ll act): x(0), y(0), pointX(true), in(in), act(act), isEnd(false) {
        if (act == 0) { isEnd = true; isAct = false; return; }
        if (act == 1 && in == 1) { isEnd = true; isAct = true; return; }
        ll goR = min(in/2, act);
        x = new Switch(in/2, act-goR);
        y = new Switch(in/2, goR);
    }

    ll dfs (ll &timer, vll &toX, vll &toY) {
        if (isEnd) return 15;
        id = timer--;
        toX[-id-1] = x->dfs(timer, toX, toY);
        toY[-id-1] = y->dfs(timer, toX, toY);
        return id;
    }

    pair <ll, ll> trig (ll par, ll st) {
        if (isEnd) return isAct ? pair <ll, ll>{ par, st } : pair <ll, ll>{ par, st+2 };
        if (pointX ^= 1)
            return y->trig(id, 0);
        else
            return x->trig(id, 1);
    }
};

void create_circuit (int m, vi A) {
    vll ve(A.begin(), A.end());
    ve.push_back(0);
    ll n = ve.size();
    if (n == 2) { // bruh edge case
        vi to(m+1, 0);
        to[0] = ve[0];
        answer(to, {}, {});
        return;
    }
    ll pow2 = 2<<__lg(n-1);
    ll timer = -1;
    Switch root(pow2, n);
    vll toX(pow2, 15), toY(pow2, 15);
    ll rootId = root.dfs(timer, toX, toY);
    ll c = 0;
    for (ll i = 0; i < pow2; i++) {
        auto [a, st] = root.trig(17, false);
        a = -a-1;
        if (st >= 2) {
            (st-2 ? toX : toY)[a] = rootId;
            continue;
        }
        (st ? toX : toY)[a] = ve[c];
        c++;
    }
    ll sz = -min(*min_element(toX.begin(), toX.end()), *min_element(toY.begin(), toY.end()));
    toX.resize(sz);
    toY.resize(sz);
    answer(vi(m+1, -1), vi(toX.begin(), toX.end()), vi(toY.begin(), toY.end()));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 39 ms 13388 KB Output is correct
3 Correct 35 ms 13292 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 5 ms 1116 KB Output is correct
6 Correct 53 ms 18764 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 39 ms 13388 KB Output is correct
3 Correct 35 ms 13292 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 5 ms 1116 KB Output is correct
6 Correct 53 ms 18764 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 65 ms 26444 KB Output is correct
9 Correct 68 ms 26700 KB Output is correct
10 Correct 116 ms 39476 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 39 ms 13388 KB Output is correct
3 Correct 35 ms 13292 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 5 ms 1116 KB Output is correct
6 Correct 53 ms 18764 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 65 ms 26444 KB Output is correct
9 Correct 68 ms 26700 KB Output is correct
10 Correct 116 ms 39476 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 432 KB Output is correct
14 Correct 117 ms 37688 KB Output is correct
15 Correct 67 ms 26188 KB Output is correct
16 Correct 104 ms 38196 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 112 ms 38732 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 65 ms 24908 KB Output is correct
3 Correct 66 ms 24824 KB Output is correct
4 Correct 102 ms 37308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 65 ms 24908 KB Output is correct
3 Correct 66 ms 24824 KB Output is correct
4 Correct 102 ms 37308 KB Output is correct
5 Correct 108 ms 36068 KB Output is correct
6 Correct 107 ms 37428 KB Output is correct
7 Correct 103 ms 36052 KB Output is correct
8 Correct 108 ms 37340 KB Output is correct
9 Correct 70 ms 24908 KB Output is correct
10 Correct 96 ms 35756 KB Output is correct
11 Correct 104 ms 36920 KB Output is correct
12 Correct 64 ms 24908 KB Output is correct
13 Correct 62 ms 25164 KB Output is correct
14 Correct 66 ms 25168 KB Output is correct
15 Correct 64 ms 25164 KB Output is correct
16 Correct 2 ms 1116 KB Output is correct
17 Correct 60 ms 22864 KB Output is correct
18 Correct 62 ms 25068 KB Output is correct
19 Correct 61 ms 24912 KB Output is correct
20 Correct 104 ms 35640 KB Output is correct
21 Correct 105 ms 35636 KB Output is correct
22 Correct 110 ms 35864 KB Output is correct