Submission #1024766

#TimeUsernameProblemLanguageResultExecution timeMemory
1024766ZicrusMechanical Doll (IOI18_doll)C++17
100 / 100
92 ms15356 KiB
#include <bits/stdc++.h> #include "doll.h" using namespace std; typedef long long ll; vector<int> C, X, Y, state; int connect(int a, int bSize, int b, int orig = 0, int mask = 0, int bit = 0) { if (!bit && orig) return b; X.push_back(0); Y.push_back(0); int id = X.size() - 1; bool first = false; if (!orig) { first = true; orig = -X.size(); mask = bSize - 1; if (mask == 0) { X.pop_back(); Y.pop_back(); return b; } bit = 1 << (int)log2(mask); } if (mask & bit) { X[id] = connect(a, bSize - (1 << ((int)log2(bSize) - 1)), b, orig, mask, bit >> 1); Y[id] = connect(a, 1 << ((int)log2(bSize) - 1), b, orig, ~0, bit >> 1); } else { X[id] = orig; Y[id] = connect(a, 1 << ((int)log2(bSize) - 1), b, orig, mask, bit >> 1); } if (first) { Y[X.size() - 1] = 0; } return -id - 1; } void create_circuit(int M, vector<int> A) { A.push_back(0); C = vector<int>(M + 1); X = vector<int>(); Y = vector<int>(); vector<vector<int>> adj(M + 1); int prev = 0; for(auto &e : A) { adj[prev].push_back(e); prev = e; } C[0] = connect(0, A.size(), 1); for (int i = 1; i < adj.size(); i++) { C[i] = C[0]; } state = vector<int>(X.size()); int pos = 0; for (int i = 0; i < A.size(); i++) { int prev = pos; do { prev = pos; if (pos >= 0) { pos = C[pos]; } else { pos = state[-pos - 1] ? Y[-pos - 1] : X[-pos - 1]; state[-prev - 1] = !state[-prev - 1]; } } while (pos < 0); if (pos != A[i]) { (!state[-prev - 1] ? Y[-prev - 1] : X[-prev - 1]) = A[i]; pos = A[i]; } } answer(C, X, Y); return; }

Compilation message (stderr)

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