답안 #787686

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
787686 2023-07-19T10:55:19 Z Magikarp4000 자동 인형 (IOI18_doll) C++17
100 / 100
105 ms 10384 KB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int(1e9+7)
#define ln '\n' 
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define PB push_back
#define in(v,x) (v.find(x) != v.end())
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
const ll LLINF = 1e18+1;

const int MAXN = 6e5+20;
int n,m;
vector<int> a,c,x,y;
bool z[MAXN], t[MAXN];
int cnt,pos;

void solve(int s, int l, int r) {
    if (l == r) {
        if (cnt < n) cnt++, z[s] = 1;
        else z[s] = 0;
        return;
    }
    int mid = (l+r)/2;
    solve(s*2+1,mid+1,r);
    solve(s*2,l,mid);
    z[s] = z[s*2] || z[s*2+1];
}

void solve1(int s, int idx, int l, int r) {
    if (!z[s]) return;
    if (l+1 == r) {
        if (!z[s*2+1]) y[idx] = -1;
        else y[idx] = -INF;
        if (!z[s*2]) x[idx] = -1;
        else x[idx] = -INF;
        return;
    }
    int mid = (l+r)/2;
    if (z[s*2+1]) y[idx] = pos--;
    else y[idx] = -1;
    if (z[s*2]) x[idx] = pos--;
    else x[idx] = -1;
    solve1(s*2+1,-y[idx]-1,mid+1,r);
    solve1(s*2,-x[idx]-1,l,mid);
}

void set_exits() {
    int cur = -1, idx = 1;
    while (idx <= n) {
        int i = -cur-1;
        if (t[i] == 0) {
            if (x[i] == -INF) x[i] = a[idx++], cur = -1;
            else cur = x[i];
        }
        else {
            if (y[i] == -INF) y[i] = a[idx++], cur = -1;
            else cur = y[i];
        }
        t[i] ^= 1;
    }
}

void create_circuit(int M, vector<int> A) {
    n = A.size(), m = M;
    FOR(i,0,n) a.PB(A[i]);
    a.PB(0);
    c.PB(a[0]);
    FOR(i,1,m+1) c.PB(-1);
    int lg = ceil(log2(n)), ub = 1;
    FOR(_,0,max(1,lg)) ub *= 2;
    solve(1,0,ub-1);
    FOR(i,0,ub) x.PB(-1), y.PB(-1);
    pos = -2;
    solve1(1,0,0,ub-1);
    while (!x.empty() && x.back() == -1 && y.back() == -1) x.pop_back(), y.pop_back();
    set_exits();
    answer(c,x,y);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 30 ms 4524 KB Output is correct
3 Correct 32 ms 4928 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 1612 KB Output is correct
6 Correct 43 ms 5984 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 30 ms 4524 KB Output is correct
3 Correct 32 ms 4928 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 1612 KB Output is correct
6 Correct 43 ms 5984 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 52 ms 7672 KB Output is correct
9 Correct 71 ms 9308 KB Output is correct
10 Correct 105 ms 10384 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 30 ms 4524 KB Output is correct
3 Correct 32 ms 4928 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 1612 KB Output is correct
6 Correct 43 ms 5984 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 52 ms 7672 KB Output is correct
9 Correct 71 ms 9308 KB Output is correct
10 Correct 105 ms 10384 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 84 ms 10048 KB Output is correct
15 Correct 53 ms 8304 KB Output is correct
16 Correct 77 ms 9988 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 83 ms 10176 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 45 ms 6312 KB Output is correct
3 Correct 49 ms 7268 KB Output is correct
4 Correct 74 ms 8624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 45 ms 6312 KB Output is correct
3 Correct 49 ms 7268 KB Output is correct
4 Correct 74 ms 8624 KB Output is correct
5 Correct 87 ms 10028 KB Output is correct
6 Correct 80 ms 9180 KB Output is correct
7 Correct 82 ms 9256 KB Output is correct
8 Correct 81 ms 9644 KB Output is correct
9 Correct 50 ms 7272 KB Output is correct
10 Correct 77 ms 8800 KB Output is correct
11 Correct 74 ms 8640 KB Output is correct
12 Correct 51 ms 7500 KB Output is correct
13 Correct 48 ms 6760 KB Output is correct
14 Correct 54 ms 8072 KB Output is correct
15 Correct 57 ms 8092 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 50 ms 5668 KB Output is correct
18 Correct 46 ms 6432 KB Output is correct
19 Correct 50 ms 7484 KB Output is correct
20 Correct 74 ms 9380 KB Output is correct
21 Correct 83 ms 8644 KB Output is correct
22 Correct 76 ms 8644 KB Output is correct