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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define ull unsigned ll
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
#include "speedrun.h"
vector<vll>adj;
ll par[1005];
ll tim = 0;
ll tin[1005] = {0};
ll arr[1005] = {0};
ll Next[1005];
void dfs(ll idx,ll p){
par[idx] = p;
tin[idx] = tim;
arr[tim] = idx;
tim++;
for(auto x:adj[idx]){
if(x != p){
dfs(x,idx);
}
}
}
void assignHints(int subtask, int N, int A[], int B[]){
setHintLen(20);
adj.assign(N+5,vll());
f(i,1,N){
adj[A[i]].pb(B[i]);
adj[B[i]].pb(A[i]);
}
dfs(1,0);
f(i,1,N+1){
Next[i] = arr[tin[i] + 1];
}
f(i,1,N+1){
f(j,0,10){
if(par[i] & (1LL<<j)){
setHint(i,j + 1,1);
}
if(Next[i] & (1LL<<j)){
setHint(i,j + 11,1);
}
}
}
}
void speedrun(int subtask, int N, int start){
ll cur = start;
while(cur != 1){
cur = 0;
f(j,0,10){
if(getHint(j + 1)){
cur += (1LL<<j);
}
}
assert(goTo(cur));
}
ll Next = 0;
f(j,0,10){
if(getHint(j + 11)){
Next += (1LL<<j);
}
}
while(Next != 0){
if(goTo(Next)){
cur = Next;
Next = 0;
f(j,0,10){
if(getHint(j + 11)){
Next += (1LL<<j);
}
}
}
else{
cur = 0;
f(j,0,10){
if(getHint(j + 1)){
cur += (1LL<<j);
}
}
assert(goTo(cur));
}
}
}
# | 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... |