// Om Namah Shivaya
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x, y) ((x + y - 1) / (y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep1(i, n) for(int i = 1; i <= n; ++i)
#define rev(i, s, e) for(int i = s; i >= e; --i)
#define trav(i, a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a, b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a, b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif
/*
*/
const int MOD = 1e9 + 7;
const int N = 1e3 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
#include "speedrun.h"
vector<int> adj[N];
vector<int> par(N);
vector<int> order;
void dfs(int u, int p){
par[u] = p;
order.pb(u);
trav(v,adj[u]){
if(v == p) conts;
dfs(v,u);
}
}
void assignHints(int subtask, int n, int A[], int B[]) { /* your solution here */
rep1(i,n-1){
int u = A[i], v = B[i];
adj[u].pb(v), adj[v].pb(u);
}
dfs(1,-1);
setHintLen(20);
rep(i,n){
// first 10 bits = par
// next 10 bits = next guy in tin time order
int u = order[i];
if(u != 1){
int p = par[u];
rep(bit,10){
int b = 0;
if(p & (1<<bit)) b = 1;
setHint(u,bit+1,b);
}
}
if(i+1 < n){
int nxt = order[i+1];
rep(bit,10){
int b = 0;
if(nxt & (1<<bit)) b = 1;
setHint(u,bit+11,b);
}
}
}
}
void speedrun(int subtask, int n, int start) { /* your solution here */
while(start != 1){
int p = 0;
rep(bit,10){
if(getHint(bit+1)){
p |= (1<<bit);
}
}
goTo(p);
start = p;
}
int vis_cnt = 1;
int u = 1;
while(vis_cnt < n){
int v = 0;
rep(bit,10){
if(getHint(bit+11)){
v |= (1<<bit);
}
}
// will fail at most 2n times, because we visit nodes in order of their in times
while(!goTo(v)){
goTo(par[u]);
u = par[u];
}
par[v] = u;
u = v;
vis_cnt++;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
141 ms |
724 KB |
Output is correct |
2 |
Correct |
192 ms |
672 KB |
Output is correct |
3 |
Correct |
149 ms |
732 KB |
Output is correct |
4 |
Correct |
124 ms |
752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
712 KB |
Output is correct |
2 |
Correct |
175 ms |
1060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
200 ms |
672 KB |
Output is correct |
2 |
Correct |
125 ms |
748 KB |
Output is correct |
3 |
Correct |
117 ms |
736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
163 ms |
728 KB |
Output is correct |
2 |
Correct |
134 ms |
672 KB |
Output is correct |
3 |
Correct |
160 ms |
708 KB |
Output is correct |
4 |
Correct |
170 ms |
728 KB |
Output is correct |
5 |
Correct |
196 ms |
684 KB |
Output is correct |
6 |
Correct |
115 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
162 ms |
712 KB |
Output is correct |
2 |
Correct |
144 ms |
716 KB |
Output is correct |
3 |
Correct |
143 ms |
712 KB |
Output is correct |
4 |
Correct |
152 ms |
724 KB |
Output is correct |
5 |
Correct |
134 ms |
724 KB |
Output is correct |
6 |
Correct |
149 ms |
676 KB |
Output is correct |
7 |
Correct |
83 ms |
708 KB |
Output is correct |