Submission #414595

#TimeUsernameProblemLanguageResultExecution timeMemory
414595schseMechanical Doll (IOI18_doll)C++17
15 / 100
246 ms34492 KiB
#include "doll.h" #ifndef EVAL #include "grader.cpp" #endif #include <bits/stdc++.h> using namespace std; vector<int> C, X, Y; struct node { unordered_set<int> options; vector<int> folowing; int visited = 0; }; vector<node> g; void rec(int index, int value, vector<bool> &tree, vector<int> &X, vector<int> &Y) { if (index > (tree.size() - 1) / 2) { if (tree[index]) X[index - 1] = value; else Y[index - 1] = value; } else if (tree[index]) rec(index * 2, value, tree, X, Y); else rec(index * 2 + 1, value, tree, X, Y); tree[index] = !tree[index]; } pair<vector<int>, vector<int>> maketree(int offset, vector<int> const &folows) { int ends = 2; while (ends < (int)folows.size()) ends *= 2; vector<int> X(ends - 1), Y(ends - 1); vector<bool> tree(ends, true); for (int i = 1; i < ends / 2; i++) { X[i - 1] = i * -2 + offset; Y[i - 1] = i * -2 - 1 + offset; } while (ends-- != (int)folows.size()) // lose ends rec(1, -1, tree, X, Y); for (int i : folows) rec(1, i, tree, X, Y); return {X, Y}; } void create_circuit(int M, std::vector<int> A) { int N = A.size(); g.resize(M + 1); C.resize(M + 1, 0); g[0].folowing.push_back(A[0]); g[0].options.insert(A[0]); for (int i = 1; i < N; i++) { g[A[i - 1]].folowing.push_back(A[i]); g[A[i - 1]].options.insert(A[i]); } g[A[N - 1]].folowing.push_back(0); g[A[N - 1]].options.insert(0); for (int i = 0; i < M + 1; i++) { if ((int)g[i].options.size() == 1) C[i] = g[i].folowing[0]; else if (g[i].options.size() == 0) C[i] = 0; else { C[i] = -X.size() - 1; auto tmp = maketree((int)X.size(), g[i].folowing); X.insert(X.end(), tmp.first.begin(), tmp.first.end()); Y.insert(Y.end(), tmp.second.begin(), tmp.second.end()); } } answer(C, X, Y); }

Compilation message (stderr)

doll.cpp: In function 'void rec(int, int, std::vector<bool>&, std::vector<int>&, std::vector<int>&)':
doll.cpp:20:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |   if (index > (tree.size() - 1) / 2)
      |       ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...