제출 #415004

#제출 시각아이디문제언어결과실행 시간메모리
415004schse자동 인형 (IOI18_doll)C++17
0 / 100
2 ms460 KiB
#include "doll.h" #ifndef EVAL #include "grader.cpp" #endif #include <bits/stdc++.h> using namespace std; struct node { vector<int> follow; set<int> options; }; vector<node> g; vector<int> C, X, Y; int mx = 2; vector<bool> tree((1 << 18) + 5, true); void rec(int index, int value) { if (index >= mx / 2) { if (tree[index]) X[index - 1] = value; else Y[index - 1] = value; } else if (tree[index]) rec(index * 2, value); else rec(index * 2 + 1, value); tree[index] = !tree[index]; } void create_circuit(int M, std::vector<int> A) { int N = A.size(); while (N >= (mx = mx * 2) * 2) ; { // built graph g.resize(M + 1); g[0].follow.push_back(A[0]); g[0].options.insert(A[0]); for (int i = 1; i < N; i++) { g[A[i - 1]].follow.push_back(A[i]); g[A[i - 1]].options.insert(A[i]); } g[A[N - 1]].follow.push_back(0); g[A[N - 1]].options.insert(0); } int toeliminate = N - mx; toeliminate++; C.resize(M + 1); fill(C.begin(), C.end(), -1); // eliminate unnecessary for (int i = 0; i < M + 1; i++) { if (g[i].options.size() == 1) { toeliminate -= g[i].follow.size(); C[i] = g[i].follow.back(); } else if (g[i].options.empty()) C[i] = 0; } assert(toeliminate <= 0); for (int i = 1; i < mx / 2; i++) { X[i - 1] = i * -2; Y[i - 1] = i * -2 - 1; } for (int i = 1; i < N; i++) { if (C[A[i - 1]] == -1) rec(1, A[i]); } Y[Y.size() - 1] = 0; 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...