Submission #448378

#TimeUsernameProblemLanguageResultExecution timeMemory
448378JovanBMechanical Doll (IOI18_doll)C++17
100 / 100
124 ms11936 KiB
#include "doll.h" #include <bits/stdc++.h> using namespace std; const int MAXC = 1000000; int L[MAXC]; int R[MAXC]; bool state[MAXC]; int tjm = 1; vector <int> C; void init(int node, int n, int d){ if(d == 1){ R[node] = MAXC; if(n == 1) L[node] = 1; else L[node] = MAXC; return; } R[node] = ++tjm; int desno = min(n, (1 << (d-1))); init(R[node], desno, d-1); n -= desno; if(n == 0){ L[node] = 1; } else{ L[node]= ++tjm; init(L[node], n, d-1); } } void descend(int node, int x){ if(!state[node]){ state[node] ^= 1; if(L[node] == MAXC){ L[node] = -x; return; } descend(L[node], x); } else{ state[node] ^= 1; if(R[node] == MAXC){ R[node] = -x; return; } descend(R[node], x); } } void create_circuit(int M, std::vector<int> A) { A.push_back(0); int n = A.size(); for(int i=0; i<=M; i++) C.push_back(-1); int d = 0; while((1 << d) < n) d++; init(1, n, d); for(int i=0; i<n; i++){ descend(1, A[i]); } vector <int> _l, _r; for(int i=0; i<tjm; i++){ _l.push_back(-L[i+1]); _r.push_back(-R[i+1]); } answer(C, _l, _r); }
#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...