제출 #415089

#제출 시각아이디문제언어결과실행 시간메모리
415089schse자동 인형 (IOI18_doll)C++17
12 / 100
192 ms28260 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(); A.push_back(0); 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]); } } C.resize(M + 1); fill(C.begin(), C.end(), -1); C[0] = A[0]; // eliminate unnecessary int toeliminate = N - mx; for (int i = 1; i < M + 1; i++) { if (g[i].options.size() == 1 && toeliminate > 0) { toeliminate -= g[i].follow.size(); C[i] = g[i].follow.back(); } else if (g[i].options.empty()) C[i] = 0; } if (toeliminate > 0) { for (int i = 0; i < M + 1; i++) { if (g[i].follow.size() == 2) { toeliminate -= 2; X.push_back(g[i].follow[0]); Y.push_back(g[i].follow[1]); C[i] = -X.size(); } else if (g[i].options.size() == 2 && g[i].follow.size() % 2 == 2) { bool b = true; for (int e = 0; e < g[i].follow.size(); e++) b &= (g[i].follow[e] == g[i].follow[e % 2]); if (b) { toeliminate -= 2; X.push_back(g[i].follow[0]); Y.push_back(g[i].follow[1]); C[i] = -X.size(); } } if (toeliminate <= 0) break; } } int offset = X.size(); for (int i = 0; i < mx - 1; i++) { X.push_back(-offset - 1); Y.push_back(-offset - 1); } for (int i = 1; i < mx / 2; i++) { X[i - 1 + offset] = i * -2 - offset; Y[i - 1 + offset] = i * -2 - 1 - offset; } bool b = false; int last = -1; for (int i = 1; i < N + 1; i++) { if (!b && C[A[i - 1]] == -1) { last = A[i]; b = true; } else if (C[A[i - 1]] == -1) { rec(1, last); last = A[i]; } } Y[Y.size() - 1] = last; if (b) answer(C, X, Y); else answer(C, {}, {}); }

컴파일 시 표준 에러 (stderr) 메시지

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:86:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |         for (int e = 0; e < g[i].follow.size(); e++)
      |                         ~~^~~~~~~~~~~~~~~~~~~~
#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...