Submission #587082

#TimeUsernameProblemLanguageResultExecution timeMemory
587082kamelfanger83Mechanical Doll (IOI18_doll)C++14
0 / 100
1 ms212 KiB
#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] = -cs; self(self, height-1); Y[root] = -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] = -cs; buildfull(buildfull, height-1); if((n - (1<<(height-1))) > 0){ Y[root] = -cs; buildpartial(n - (1<<(height-1)), height-1); } else Y[root] = -1; } else{ X[root] = -cs; buildpartial(n, height-1); Y[root] = -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] == 0){ if(ca == N){ assert(false); } X[-c] = A[ca++]; } c = X[-c]; } else if(sparity[-c] == true){ if(Y[-c] == 0){ if(ca == N){ Y[-c] = 0; goto ans; } Y[-c] = A[ca++]; } c = Y[-c]; } 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 = {2,3,1,4,5,7,6,8,9}; create_circuit(9, A); }*/
#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...