Submission #416539

#TimeUsernameProblemLanguageResultExecution timeMemory
416539wiwihoMechanical Doll (IOI18_doll)C++14
37 / 100
155 ms11156 KiB
#include "doll.h"

#include <bits/stdc++.h>

#define eb emplace_back
#define printv(a, b) { \
    for(auto pv : a) b << pv << " "; \
    b << "\n"; \
}

using namespace std;

int n, m;
vector<int> a;
vector<int> x, y;
int s;

vector<bool> state;
int go = 0;
int dfs(int now){
    if(now == 0) return go;
    if(!state[now - 1]){
        state[now - 1] = true;
        x[now - 1] = dfs(-x[now - 1]);
    }
    else{
        state[now - 1] = false;
        y[now - 1] = dfs(-y[now - 1]);
    }
    return -now;
}

void create_circuit(int _m, vector<int> _a){
    m = _m;
    a = _a;
    n = a.size() + 1;

    int leaf = 1;
    int s = 1;
    while(leaf * 2 < n){
        leaf *= 2;
        s += leaf;
    }
    x.resize(s);
    y.resize(s);

    for(int i = 1; i <= s; i++){
        if(2 * i <= s) x[i - 1] = - (2 * i);
        if(2 * i + 1 <= s) y[i - 1] = - (2 * i + 1);
    }
    //cerr << leaf * 2 << "\n";
    //printv(x, cerr);
    //printv(y, cerr);

    vector<int> c(m + 1, -1);
    state.resize(s);

    for(int i = 0; i < n - 1; i++){
        go = a[i];
        dfs(1);
    }
    for(int i = n - 1; i < leaf * 2 - 1; i++){
        go = -1;
        dfs(1);
        //cerr << "temp\n";
    }
    go = 0;
    dfs(1);

    //printv(x, cerr);
    //printv(y, cerr);
    
    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...