제출 #525719

#제출 시각아이디문제언어결과실행 시간메모리
525719byunjaewoo자동 인형 (IOI18_doll)C++17
0 / 100
3 ms4940 KiB
#include "doll.h" #include <bits/stdc++.h> using namespace std; using ll=long long; const int Nmax=200010; int M, N, cnt, Size, A[Nmax]; int out[Nmax], X[2*Nmax], Y[2*Nmax]; bool st[Nmax]; vector<int> V[Nmax]; void DFS(int curr, int s, int e) { if(e-s==1) { X[-curr]=Y[-curr]=INT_MAX; if(s<=Size-N) X[-curr]=-1; return; } int m=(s+e)/2; if(m<=Size-N) X[-curr]=-1; else { X[-curr]=--cnt; DFS(X[-curr], s, m); } Y[-curr]=--cnt; DFS(Y[-curr], m+1, e); } void create_circuit(int M, vector<int> A) { A.push_back(0); N=A.size(); Size=(1<<(32-__builtin_clz(N-1))); out[0]=--cnt; DFS(out[0], 1, Size); for(int i=1; i<=N; i++) { for(int curr=-1; ; ) { st[-curr]^=1; if(!st[-curr]) { if(Y[-curr]==INT_MAX) { Y[-curr]=A[i-1]; break; } curr=Y[-curr]; } else { if(X[-curr]==INT_MAX) { X[-curr]=A[i-1]; break; } curr=X[-curr]; } } } vector<int> C, l, r; for(int i=0; i<=M; i++) C.push_back(out[i]); for(int i=1; i<=-cnt; i++) { l.push_back(X[i]); r.push_back(Y[i]); } 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...