// 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);
}
}
while(true){
bool ok = goTo(v);
if(ok) break;
goTo(par[u]);
u = par[u];
}
par[v] = u;
u = v;
vis_cnt++;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
137 ms |
672 KB |
Output is correct |
2 |
Correct |
179 ms |
752 KB |
Output is correct |
3 |
Correct |
149 ms |
716 KB |
Output is correct |
4 |
Correct |
128 ms |
740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
115 ms |
740 KB |
Output is correct |
2 |
Correct |
194 ms |
704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
672 KB |
Output is correct |
2 |
Correct |
161 ms |
676 KB |
Output is correct |
3 |
Correct |
168 ms |
704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
175 ms |
716 KB |
Output is correct |
2 |
Correct |
214 ms |
672 KB |
Output is correct |
3 |
Correct |
124 ms |
760 KB |
Output is correct |
4 |
Correct |
132 ms |
672 KB |
Output is correct |
5 |
Correct |
203 ms |
792 KB |
Output is correct |
6 |
Correct |
139 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
184 ms |
672 KB |
Output is correct |
2 |
Correct |
144 ms |
672 KB |
Output is correct |
3 |
Correct |
188 ms |
716 KB |
Output is correct |
4 |
Correct |
138 ms |
708 KB |
Output is correct |
5 |
Correct |
183 ms |
672 KB |
Output is correct |
6 |
Correct |
119 ms |
676 KB |
Output is correct |
7 |
Correct |
185 ms |
736 KB |
Output is correct |