답안 #1077255

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077255 2024-08-27T04:10:42 Z onbert 자동 인형 (IOI18_doll) C++17
53 / 100
121 ms 19704 KB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5, maxm = 1e5 + 5, maxN = 4e5 + 5;
int n, m;
vector<int> a;
int cnt = 0;
vector<int> adj[maxm];
vector<int> nxt, l, r;
bool on[maxN];

void build(int u, int sz) {
    if (sz == 1) return;
    l.push_back(0), r.push_back(0);
    l.push_back(0), r.push_back(0);
    cnt--, l[-u-1] = cnt;
    cnt--, r[-u-1] = cnt;
    build(l[-u-1], sz-1); build(r[-u-1], sz-1);
}

void create_circuit(int M, vector<int> A) {
    m = M, a = A;
    n = a.size();
    for (int i=0;i<n-1;i++) adj[a[i]].push_back(a[i+1]);
    adj[a[n-1]].push_back(0);
    nxt.resize(m+1);
    nxt[0] = a[0];
    for (int i=1;i<=m;i++) {
        // cout << i << endl;
        if (adj[i].size()==0) continue;
        if (adj[i].size()==1) {
            nxt[i] = adj[i][0];
            continue;
        }
        cnt--;
        l.push_back(0), r.push_back(0);
        // cout << cnt << " " << l.size() << " " << r.size() << endl;
        int rt = cnt;
        nxt[i] = cnt;
        int sz = log2(adj[i].size() - 1) + 1;
        build(rt, sz);
        sz = (1<<sz);
        int delta = sz - adj[i].size();
        // cout << delta << endl;
        // cout << i << endl;
        // for (int x:adj[i]) cout << x << " "; cout << endl;
        for (int j=0;j<sz;j++) {
            int u = rt;
            while (l[-u-1] != 0 && r[-u-1] != 0) {
                if (on[-u-1]) {
                    on[-u-1] = !on[-u-1];
                    u = r[-u-1];
                } else {
                    on[-u-1] = !on[-u-1];
                    u = l[-u-1];
                }
            }
            // cout << u << " " << on[u] << " " << j << " " << j-delta << " " << adj[i][j-delta] << endl;
            if (on[-u-1]) {
                on[-u-1] = !on[-u-1];
                if (j-delta < 0) r[-u-1] = rt;
                else r[-u-1] = adj[i][j-delta];
            } else {
                on[-u-1] = !on[-u-1];
                if (j-delta < 0) l[-u-1] = rt;
                else l[-u-1] = adj[i][j-delta];
            }
        }
        // cout << l.size() << endl;
        // for (int j=0;j<l.size();j++) cout << l[j] << " " << r[j] << endl;
    }
    // cout << l.size() << endl;
    // for (int i=0;i<l.size();i++) cout << l[i] << " " << r[i] << endl;
    // int u = 0;
    // while (true) {
    //     // if (u>=0) cout << u << endl;
    //     if (u>=0) u = nxt[u];
    //     else if (on[-u-1]) {
    //         on[-u-1] = !on[-u-1];
    //         u = r[-u-1];
    //     } else {
    //         on[-u-1] = !on[-u-1];
    //         u = l[-u-1];
    //     }
    //     if (u==0) break;
    // }
    answer(nxt, l, r);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 24 ms 7008 KB Output is correct
3 Correct 13 ms 7000 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 7 ms 3932 KB Output is correct
6 Correct 21 ms 8852 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 24 ms 7008 KB Output is correct
3 Correct 13 ms 7000 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 7 ms 3932 KB Output is correct
6 Correct 21 ms 8852 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 52 ms 9688 KB Output is correct
9 Correct 33 ms 10196 KB Output is correct
10 Correct 49 ms 13508 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 24 ms 7008 KB Output is correct
3 Correct 13 ms 7000 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 7 ms 3932 KB Output is correct
6 Correct 21 ms 8852 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 52 ms 9688 KB Output is correct
9 Correct 33 ms 10196 KB Output is correct
10 Correct 49 ms 13508 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 54 ms 15152 KB Output is correct
15 Correct 59 ms 9144 KB Output is correct
16 Correct 47 ms 12564 KB Output is correct
17 Correct 2 ms 2648 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 78 ms 13988 KB Output is correct
21 Correct 2 ms 2856 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 2 ms 2652 KB Output is partially correct
2 Correct 38 ms 9164 KB Output is correct
3 Partially correct 79 ms 12276 KB Output is partially correct
4 Partially correct 121 ms 13808 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 2 ms 2652 KB Output is partially correct
2 Correct 38 ms 9164 KB Output is correct
3 Partially correct 79 ms 12276 KB Output is partially correct
4 Partially correct 121 ms 13808 KB Output is partially correct
5 Partially correct 64 ms 17176 KB Output is partially correct
6 Partially correct 69 ms 18540 KB Output is partially correct
7 Partially correct 79 ms 17920 KB Output is partially correct
8 Partially correct 73 ms 19072 KB Output is partially correct
9 Partially correct 66 ms 13312 KB Output is partially correct
10 Partially correct 102 ms 19488 KB Output is partially correct
11 Partially correct 74 ms 19704 KB Output is partially correct
12 Partially correct 47 ms 13760 KB Output is partially correct
13 Partially correct 46 ms 13064 KB Output is partially correct
14 Partially correct 45 ms 12652 KB Output is partially correct
15 Partially correct 43 ms 12100 KB Output is partially correct
16 Partially correct 3 ms 2908 KB Output is partially correct
17 Partially correct 41 ms 11588 KB Output is partially correct
18 Partially correct 38 ms 11592 KB Output is partially correct
19 Partially correct 40 ms 12196 KB Output is partially correct
20 Partially correct 56 ms 15276 KB Output is partially correct
21 Partially correct 67 ms 17512 KB Output is partially correct
22 Partially correct 49 ms 14312 KB Output is partially correct