# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
498930 | dxz05 | Speedrun (RMI21_speedrun) | C++14 | 126 ms | 1008 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "speedrun.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> g;
int ord[1001];
vector<int> vec;
void dfs(int v, int p){
ord[v] = vec.size();
vec.push_back(v);
if (v != p){
for (int i = 0; i < 10; i++){
if (p & (1 << i)) setHint(v, i + 11, true);
}
}
for (int u : g[v]){
if (u != p){
dfs(u, v);
}
}
}
void assignHints(int subtask, int N, int A[], int B[]) {
setHintLen(20);
g.resize(N + 1);
for (int i = 1; i < N; i++){
g[A[i]].push_back(B[i]);
g[B[i]].push_back(A[i]);
}
dfs(1, 1);
for (int i = 1; i <= N; i++){
int j = vec[(ord[i] + 1) % N];
for (int k = 0; k < 10; k++){
if (j & (1 << k)) setHint(i, k + 1, true);
}
}
}
int get_next(){
int v = 0;
for (int i = 0; i < 10; i++){
if (getHint(i + 1)) v |= 1 << i;
}
return v;
}
int get_parent(){
int v = 0;
for (int i = 0; i < 10; i++){
if (getHint(i + 11)) v |= 1 << i;
}
return v;
}
void speedrun(int subtask, int N, int start) {
set<int> vis;
vis.insert(start);
int x = start;
while (vis.size() < N){
int u = get_next();
if (u > 0 && goTo(u)){
x = u;
vis.insert(u);
continue;
}
while (true){
int v = get_parent();
if (vis.size() == N) return;
if (v > 0){
if (goTo(v)){
x = v;
vis.insert(v);
}
}
if (vis.size() == N) return;
if (goTo(u)){
x = u;
vis.insert(u);
break;
}
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |