Submission #767074

#TimeUsernameProblemLanguageResultExecution timeMemory
767074oyberMechanical Doll (IOI18_doll)C++14
0 / 100
1 ms212 KiB
#include "doll.h" #include <cstdio> using namespace std; vector<int> c; vector<int> xs; vector<int> ys; vector<int> a; int ai = 0; int n = 0; struct Switch; extern Switch* switches; int add_switch(Switch); struct Switch { int x; int y; int state; void gen_childs(int num) { if (num == 2) { xs.push_back(0); ys.push_back(0); return; } if (num == 3) { Switch s = Switch{0, 0, 0}; x = add_switch(s); xs.push_back(-x); ys.push_back(0); switches[x].gen_childs(2); return; } Switch s1 = Switch{0, 0, 0}; x = add_switch(s1); xs.push_back(-x); Switch s2 = Switch{0, 0, 0}; y = add_switch(s2); ys.push_back(-y); switches[x].gen_childs(num/2); switches[y].gen_childs(num-num/2); } int get() { int next = x; if (state == 1) next = y; state = !state; return next; } }; #define NUM_SWITCHES 1000000 Switch switches2[NUM_SWITCHES]; Switch* switches = switches2; int index = 1; int add_switch(Switch s) { switches[index] = s; index++; return index-1; } void sim_switches(int s) { int next = switches[s].get(); if (next == 0) { if (ai < n) { next = a[ai]; if (switches[s].state == 1) { xs[s-1] = next; //printf("x: (%d %d)\n", s-1, next); } else { ys[s-1] = next; //printf("x: (%d %d)\n", s-1, next); } ai++; sim_switches(1); } return; } sim_switches(next); } void create_circuit(int M, std::vector<int> A) { a = A; int N = A.size(); n = N; int s = add_switch(Switch{0,0,0}); switches[s].gen_childs(N); sim_switches(1); vector<int> C(M + 1); C[0] = -1; for (int i = 1; i <= M; ++i) { C[i] = -1; } C[A[N-1]] = 0; /*printf("C: "); for (int i = 0; i <= M; i++) { printf("%d, ", C[i]); } printf("\n"); printf("X: "); for (int i = 0; i < int(xs.size()); i++) { printf("%d, ", xs[i]); } printf("\n"); printf("Y: "); for (int i = 0; i < int(ys.size()); i++) { printf("%d, ", ys[i]); } printf("\n"); */ answer(C, xs, ys); }
#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...