Submission #362884

# Submission time Handle Problem Language Result Execution time Memory
362884 2021-02-04T15:03:42 Z benedict0724 Mechanical Doll (IOI18_doll) C++17
100 / 100
142 ms 13072 KB
#include "doll.h"
#include <queue>
#include <stdio.h>

int x[400002], y[400002];

void change(int M, std::vector<int> &C, std::vector<int> &X, std::vector<int> &Y, std::vector<int> A){
    std::queue<int> q;
    A.push_back(0);
    int L = (int)A.size();

    for(int i=0;i<=M;i++) C[i] = -1;

    for(int i=0;i<=400000;i++){
        x[i] = 1;
        y[i] = 1;
    }

    int h = 0;
    while((1<<h) < L) h++;
    L = (1<<h) - L;

    q.push(1);

    int cnt = 1;

    for(int i=h-1;i>=0;i--){
        std::queue<int> temp;
        int now = q.front(); q.pop();
        if(i == 0 && (1&L)){
            x[now] = -1;
        }
        if(i == 0) break;

        if((1<<i) & L){
            x[now] = -1;
            ++cnt; y[now] = -cnt; temp.push(cnt);
        }
        else{
            ++cnt; x[now] = -cnt; temp.push(cnt);
            ++cnt; y[now] = -cnt; temp.push(cnt);
        }
        while(!q.empty()){
            int now = q.front(); q.pop();
            ++cnt; x[now] = -cnt; temp.push(cnt);
            ++cnt; y[now] = -cnt; temp.push(cnt);
        }
        while(!temp.empty()){
            int now = temp.front(); temp.pop();
            q.push(now);
        }
    }

    std::vector<bool> visited(cnt);
    X.resize(cnt); Y.resize(cnt);

    for(int i=0;i<cnt;i++){
        X[i] = x[i+1];
        Y[i] = y[i+1];
    }

    for(int i=0;i<(1<<h) - L;i++){
        int curr = -1;
        for(;;){
            if(!visited[-curr-1]){
                visited[-curr-1] = true;
                if(x[-curr] == 1) { X[-curr-1] = A[i]; break; }
                else curr = x[-curr];
            }
            else{
                visited[-curr-1] = false;
                if(y[-curr] == 1) { Y[-curr-1] = A[i]; break; }
                else curr = y[-curr];
            }
        }
    }
}

void create_circuit(int M, std::vector<int> A) {
    std::vector<int> C(M + 1);
    std::vector<int> X, Y;
    change(M, C, X, Y, A);
    answer(C, X, Y);
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3404 KB Output is correct
2 Correct 44 ms 7168 KB Output is correct
3 Correct 42 ms 6856 KB Output is correct
4 Correct 3 ms 3404 KB Output is correct
5 Correct 14 ms 4556 KB Output is correct
6 Correct 81 ms 8736 KB Output is correct
7 Correct 3 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3404 KB Output is correct
2 Correct 44 ms 7168 KB Output is correct
3 Correct 42 ms 6856 KB Output is correct
4 Correct 3 ms 3404 KB Output is correct
5 Correct 14 ms 4556 KB Output is correct
6 Correct 81 ms 8736 KB Output is correct
7 Correct 3 ms 3404 KB Output is correct
8 Correct 84 ms 9604 KB Output is correct
9 Correct 82 ms 10036 KB Output is correct
10 Correct 136 ms 13072 KB Output is correct
11 Correct 3 ms 3404 KB Output is correct
12 Correct 3 ms 3404 KB Output is correct
13 Correct 3 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3404 KB Output is correct
2 Correct 44 ms 7168 KB Output is correct
3 Correct 42 ms 6856 KB Output is correct
4 Correct 3 ms 3404 KB Output is correct
5 Correct 14 ms 4556 KB Output is correct
6 Correct 81 ms 8736 KB Output is correct
7 Correct 3 ms 3404 KB Output is correct
8 Correct 84 ms 9604 KB Output is correct
9 Correct 82 ms 10036 KB Output is correct
10 Correct 136 ms 13072 KB Output is correct
11 Correct 3 ms 3404 KB Output is correct
12 Correct 3 ms 3404 KB Output is correct
13 Correct 3 ms 3404 KB Output is correct
14 Correct 115 ms 12636 KB Output is correct
15 Correct 80 ms 9212 KB Output is correct
16 Correct 117 ms 12224 KB Output is correct
17 Correct 4 ms 3408 KB Output is correct
18 Correct 3 ms 3404 KB Output is correct
19 Correct 3 ms 3404 KB Output is correct
20 Correct 135 ms 12868 KB Output is correct
21 Correct 3 ms 3404 KB Output is correct
22 Correct 3 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 3 ms 3404 KB Output is correct
3 Correct 4 ms 3404 KB Output is correct
4 Correct 3 ms 3404 KB Output is correct
5 Correct 3 ms 3404 KB Output is correct
6 Correct 4 ms 3300 KB Output is correct
7 Correct 4 ms 3404 KB Output is correct
8 Correct 4 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 75 ms 8484 KB Output is correct
3 Correct 107 ms 8440 KB Output is correct
4 Correct 115 ms 11200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 75 ms 8484 KB Output is correct
3 Correct 107 ms 8440 KB Output is correct
4 Correct 115 ms 11200 KB Output is correct
5 Correct 129 ms 12256 KB Output is correct
6 Correct 108 ms 12068 KB Output is correct
7 Correct 142 ms 12248 KB Output is correct
8 Correct 108 ms 11900 KB Output is correct
9 Correct 79 ms 8496 KB Output is correct
10 Correct 106 ms 11872 KB Output is correct
11 Correct 118 ms 11544 KB Output is correct
12 Correct 72 ms 8720 KB Output is correct
13 Correct 71 ms 9016 KB Output is correct
14 Correct 81 ms 9052 KB Output is correct
15 Correct 76 ms 9236 KB Output is correct
16 Correct 5 ms 3532 KB Output is correct
17 Correct 67 ms 8728 KB Output is correct
18 Correct 72 ms 8596 KB Output is correct
19 Correct 69 ms 8716 KB Output is correct
20 Correct 108 ms 11740 KB Output is correct
21 Correct 108 ms 11536 KB Output is correct
22 Correct 106 ms 11540 KB Output is correct