답안 #587087

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587087 2022-07-01T09:53:06 Z kamelfanger83 자동 인형 (IOI18_doll) C++14
10 / 100
1 ms 212 KB
#include <iostream>
#include <vector>
#include "doll.h"
#include <functional>
#include <cassert>

using namespace std;

/*void answer(vector<int> C, vector<int> X, vector<int> Y){
    return;
}*/

void create_circuit(int M, vector<int> A) {
    int N = A.size();
    int cs = 1;
    vector<int> C(M + 1);
    vector<int> X (2*N, 0), Y(2*N, 0);
    C[0] = A[0];

    auto ghbit = [&](int n){
        int hbit = 0;
        for(int bit = 0; bit < 30; bit++) if((n & (1<<bit)) != 0) hbit = bit;
        return hbit;
    };

    auto buildfull = [&](auto&& self, int height){
        int root = cs;
        cs++;
        if(height == 1) return;
        X[root-1] = -cs;
        self(self, height-1);
        Y[root-1] = -cs;
        self(self, height-1);
    };

    function<void(int, int)> buildpartial = [&](int n, int height)->void{
        int root = cs;
        cs++;
        if(height == 1) return;
        if(n >= 1<<(height-1)){
            X[root-1] = -cs;
            buildfull(buildfull, height-1);
            if((n - (1<<(height-1))) > 0){
                Y[root-1] = -cs;
                buildpartial(n - (1<<(height-1)), height-1);
            }
            else Y[root-1] = -1;
        }
        else{
            X[root-1] = -cs;
            buildpartial(n, height-1);
            Y[root-1] = -1;
        }
        cs++;
    };

    buildpartial(N, ghbit(N)+1);

    swap(X, Y);

    for(int rooter = 1; rooter <= M; rooter++) C[rooter] = -1;
    int ca = 1;
    vector<bool> sparity (2*N, 0);
    int c = A[0];
    while(true){
        if(c >= 0) c = C[c];
        else{
            int oc = c;
            if(sparity[-c] == false){
                if(X[-c-1] == 0){
                    if(ca == N){
                        assert(false);
                    }
                    X[-c-1] = A[ca++];
                }
                c = X[-c-1];
            }
            else if(sparity[-c] == true){
                if(Y[-c-1] == 0){
                    if(ca == N){
                        Y[-c-1] = 0;
                        goto ans;
                    }
                    Y[-c-1] = A[ca++];
                }
                c = Y[-c-1];
            }
            sparity[-oc] = !sparity[-oc];
        }
    }
    ans:
    int S = X.size(); while(X[S-1] == 0){X.pop_back(); S--;}
    Y.resize(S); 
    answer(C, X, Y);
}

/*int main(){
    vector<int> A = {1,2};
    create_circuit(2, A);
}*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB state 'Y'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB state 'Y'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB state 'Y'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 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 Incorrect 1 ms 212 KB state 'Y'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB state 'Y'
2 Halted 0 ms 0 KB -