제출 #97071

#제출 시각아이디문제언어결과실행 시간메모리
97071dlalswp25자동 인형 (IOI18_doll)C++14
100 / 100
141 ms13168 KiB
#include "doll.h" #include <bits/stdc++.h> using namespace std; vector<int> C, X, Y, A; int N, M; int id; int x[202020]; int y[202020]; int s[202020]; int mid = 0; int build2k(int b) { int now = ++id; if(b == 2) { x[now] = y[now] = -1; return now; } x[now] = build2k(b / 2); y[now] = build2k(b / 2); return now; } int build(int n, int b) { //printf("%d %d\n", n, b); int now = ++id; if(n == 1 && b == 1) { x[now] = 1; y[now] = -1; return now; } if(n == b) { x[now] = 1; y[now] = build2k(b); return now; } if(n < b) { x[now] = 1; y[now] = build(n, b / 2); return now; } x[now] = build2k(b); y[now] = build(n - b, b / 2); return now; } void simu() { int now = 1; while(1) { s[now] = !s[now]; if(!s[now]) { /// y if(y[now] == -1) { --mid; if(mid < -N + 1) { y[now] = 0; return; } else y[now] = -A[-mid - 1]; now = 1; } else now = y[now]; } else { /// x if(x[now] == -1) { --mid; if(mid < -N + 1) { x[now] = 0; return; } else x[now] = -A[-mid - 1]; now = 1; } else now = x[now]; } } } void create_circuit(int _M, std::vector<int> _A) { _A.push_back(0); A = _A; N = A.size(); M = _M; if(N == 2) { C.resize(M + 1); C[0] = C[A[0]] = -1; X.push_back(A[0]); Y.push_back(0); answer(C, X, Y); return; } int b = 1; while(b * 2 <= N) b <<= 1; build(N, b); simu(); for(int i = 0; i <= M; i++) C.push_back(-1); for(int i = 1; i <= id; i++) { X.push_back(-x[i]); Y.push_back(-y[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...