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;
const int sz = 2005;
int cnt, num, in[sz], t[sz], p[sz];
vector<int> g[sz];
void dfs(int v)
{
in[v] = ++cnt;
t[in[v]] = v;
for(int i : g[v])
{
if(!in[i])
{
p[i] = v;
dfs(i);
}
}
}
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]);
}
setHintLen(20);
dfs(1);
for(int i = 1; i <= N; i++)
{
int nxt = t[in[i] + 1];
int prv = p[i];
if(nxt == 0)nxt = 1;
for(int j = 0; j < 10; j++)
{
if(prv & (1 << j)) setHint(i, (j + 11), 1);
if(nxt & (1 << j)) setHint(i, (j + 1), 1);
}
}
}
void f(int go, int N)
{
if(num == N)return;
int nxt = 0, prv = 0;
for(int i = 0; i < 10; i++)
{
nxt += getHint(i + 1) * (1 << i);
prv += getHint(i + 11) * (1 << i);
}
if(go)
{
if(!goTo(go))
{
//cout << "could not go to " << go << ", went to " << prv << endl;
goTo(prv);
f(go, N);
}
else
{
num++;
//cout << "went to " << go << endl;
f(0, N);
}
}
else
{
if(!goTo(nxt))
{
goTo(prv);
//cout << "could not go to " << nxt << ", went to " << prv << endl;
f(nxt, N);
}
else
{
//cout << "went to " << nxt << endl;
num++;
f(0, N);
}
}
}
void speedrun(int subtask, int N, int start)
{
num = 1;
f(0, N);
}
# | 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... |