Submission #75133

#TimeUsernameProblemLanguageResultExecution timeMemory
75133DiuvenMechanical Doll (IOI18_doll)C++14
100 / 100
165 ms14124 KiB
#include "doll.h" typedef std::vector<int> vi; int n, m, s; vi X, Y, C; int L[400010], R[400010], rt; bool state[400010]; int B[200010]; int make_tree(){ vi Q, P; for(int i=1; i<=n; i++) Q.push_back(i); do{ for(int i=0, sz=Q.size(); i<sz; i+=2){ s++; int a=Q[i], b=(i+1<sz ? Q[i+1] : 0); L[s]=a, R[s]=b; P.push_back(-s); } Q.clear(); Q=P; P.clear(); } while(Q.size()>1U); return -Q[0]; } int find(int v=-rt){ if(v>=0) return v; int ret=find(state[-v] ? L[-v] : R[-v]); state[-v]=!state[-v]; return ret; } int f(int x){ if(x==0) return -rt; if(x<0) return x; return B[x]; } void create_circuit(int M, vi A) { n=A.size(); m=M; A.push_back(0); C.resize(m+1), C[0]=A[0]; rt=make_tree(); for(int i=1; i<=m; i++) C[i]=-rt; int pos=1; while(pos<=n){ int now=find(); if(now==0) continue; B[now]=A[pos]; pos++; } for(int i=1; i<=s; i++){ X.push_back(f(R[i])); Y.push_back(f(L[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...