Submission #260024

#TimeUsernameProblemLanguageResultExecution timeMemory
260024ChrisTMechanical Doll (IOI18_doll)C++17
53 / 100
166 ms13112 KiB
#include <bits/stdc++.h> #include "doll.h" using namespace std; void create_circuit (int m, vector<int> a) { int n = a.size(); vector<vector<int>> togo(m+1); vector<int> exit(m+1),x,y; int lst = 0; for (int i = 0; i < n; i++) { togo[lst].push_back(a[i]); lst = a[i]; } togo[lst].push_back(0); for (int j = 0; j <= m; j++) { if (togo[j].empty()) exit[j] = j; else if (togo[j].size() == 1) exit[j] = togo[j][0]; else { int levels = __lg((int)togo[j].size() - 1) + 1, base = (int)x.size(); x.resize(base + (1 << levels) - 1); y.resize(base + (1 << levels) - 1); vector<int> val(1 << levels); val[1] = 0; exit[j] = -(base + 1); for (int i = 1; i < (1 << (levels - 1)); i++) { x[base + i - 1] = -(base + i * 2); val[i*2] = val[i]; y[base + i - 1] = -(base + i * 2 + 1); val[i*2+1] = val[i] | (1 << __lg(i)); } int lower = (1 << levels) - (int)togo[j].size(); for (int i = (1 << (levels-1)); i < (1 << levels); i++) { int lVal = val[i], rVal = val[i] | (1 << __lg(i)); if (lVal >= lower) x[base + i - 1] = togo[j][lVal - lower]; else x[base + i - 1] = -(base + 1); if (rVal >= lower) y[base + i - 1] = togo[j][rVal - lower]; else y[base + i - 1] = -(base + 1); } } } answer(exit,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...