제출 #390435

#제출 시각아이디문제언어결과실행 시간메모리
390435ryno자동 인형 (IOI18_doll)C++14
100 / 100
118 ms8896 KiB
#include "doll.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int S, mp[400005];
vector<int> X, Y;
int ID = 0;

void dfs(int l, int r, int v = 0, int depth = 0) {
    ++ID;
    if (l + 1 == r) {
        if (l < S) X.push_back(-1);
        else X.push_back(v);
        Y.push_back(v | (1 << depth));
        return;
    }

    int cur_vtx = ID - 1;
    int m = (l + r) / 2;
    Y.push_back(69);
    if (m < S) {
        X.push_back(-1);
    }
    else {
        X.push_back(-ID - 1);
        dfs(l, m, v, depth + 1);
    }
    Y[cur_vtx] = -ID - 1;
    dfs(m + 1, r, v | (1 << depth), depth + 1);
}

void create_circuit(int M, vector<int> A) {
    if (A.size() == 1) {
        vector<int> C = { A[0], 0 }, X(0), Y(0);
        answer(C, X, Y);
        return;
    }
    
    vector<int> C;
    C.push_back(A[0]);
    A.erase(A.begin());
    A.push_back(0);
    for (int i = 0; i < M; ++i) C.push_back(-1);

    int K = ceil(log2(A.size()));
    S = (1 << K) - A.size();

    dfs(0, (1 << K) - 1);

    for (int i = 0; i < ID; i++) {
        if (X[i] >= 0) mp[X[i]] = 1;
        if (Y[i] >= 0) mp[Y[i]] = 1;
    }

    int iA = 0;
    for (int i = 0; i < (1 << K); ++i) {
        if (mp[i]) {
            mp[i] = A[iA];
            ++iA;
        }
    }

    for (int i = 0; i < ID; i++) {
        if (X[i] >= 0) X[i] = mp[X[i]];
        if (Y[i] >= 0) Y[i] = mp[Y[i]];
    }
    answer(C, X, Y);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...