Submission #742765

#TimeUsernameProblemLanguageResultExecution timeMemory
742765MilosMilutinovicSpeedrun (RMI21_speedrun)C++14
100 / 100
234 ms944 KiB
#include "speedrun.h" #include <bits/stdc++.h> using namespace std; const int N = 2002; int par[N], idx[N]; vector<int> g[N], order; void dfs(int x, int fa) { par[x] = fa; idx[x] = (int) order.size(); order.push_back(x); for (int y : g[x]) if (y != fa) dfs(y, x); } void assignHints(int subtask, int n, int a[], int b[]) { for (int i = 1; i < n; i++) { g[a[i]].push_back(b[i]); g[b[i]].push_back(a[i]); } dfs(1, 0); setHintLen(20); // printf("-- %d\n", order[idx[1] + 1]); for (int i = 1; i <= n; i++) { for (int j = 0; j < 10; j++) setHint(i, j + 1, par[i] >> j & 1); if (idx[i] + 1 < n) for (int j = 0; j < 10; j++) setHint(i, 11 + j, order[idx[i] + 1] >> j & 1); else for (int j = 0; j < 10; j++) setHint(i, 11 + j, order[idx[i] + 1] >> j & 1); } } int getPar() { int x = 0; for (int i = 0; i < 10; i++) if (getHint(i + 1)) x += (1 << i); return x; } int getChild() { int x = 0; for (int i = 0; i < 10; i++) if (getHint(i + 11)) x += (1 << i); return x; } vector<int> stk; void go(int x, int fa) { int ch = getChild(); if (ch != 0) stk.push_back(ch); // printf("trcim iz %d kid=%d\n", x, ch); while (!stk.empty()) { int y = stk.back(); if (goTo(y)) { stk.pop_back(); go(y, x); goTo(x); } else break; } } void speedrun(int subtask, int N, int start) { while (getPar() != 0) { int nxt = getPar(); goTo(nxt); start = nxt; } go(start, start); }
#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...