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<bool> get_bits(int id){
vector<bool> res(10, 0);
for(int i = 0; i<10; i++){
res[i] = ((id & (1<<i))>0);
////cout<<(id & (1<<i))<<endl;
}
return res;
}
void mySetHint(int i, int j, bool b){
int b2;
if(b){
b2 =1;
}
else{
b2 =0;
}
//cout<<"setting "<<i<<" "<<j<<" "<<b2<<endl;
setHint(i, j, b);
}
void set_anc(int u, int anc){
auto anc_b = get_bits(anc);
for(int i = 0; i<10; i++){
mySetHint(u, i+1, anc_b[i]);
}
}
void set_down(int u, int v){
auto v_b = get_bits(v);
for(int i = 10; i<20; i++){
mySetHint(u, i+1, v_b[i-10]);
}
}
void dfs(int u, int anc, vector<vector<int>>& adj, vector<int>& order){
set_anc(u, anc);
if(order.size()>0){
set_down(order.back(), u);
}
order.push_back(u);
for(auto e: adj[u]){
if(e!=anc){
dfs(e, u, adj, order);
}
}
}
void assignHints(int subtask, int N, int A[], int B[]) { /* your solution here */
setHintLen(20);
//cout<<"hello"<<endl;
vector<vector<int>> adj(N+1);
vector<int> order;
for(int i = 1; i<=N-1; i++){
int a =A[i];
int b = B[i];
adj[a].push_back(b);
adj[b].push_back(a);
}
//cout<<"hello"<<endl;
dfs(1, 1, adj, order);
set_down(order.back(), order.back());
}
int get_up(){
int res =0;
for(int i = 0; i<10; i++){
if(getHint(i+1)){
res += (1<<i);
}
}
return res;
}
int get_down(){
int res =0;
for(int i = 0; i<10; i++){
if(getHint(i+11)){
res += (1<<i);
}
}
return res;
}
bool myGoTo(int i){
bool res = goTo(i);
//cout<<"go "<<i<<" "<<res<<endl;
return res;
}
void speedrun(int subtask, int N, int start) { /* your solution here */
int cur =start;
while(get_up()!=cur){
cur = get_up();
myGoTo(cur);
}
for(int i = 0; i<N; i++){
int next = get_down();
if(next!=cur){
while(!myGoTo(next)){
myGoTo(get_up());
}
}
cur = next;
}
}
Compilation message (stderr)
speedrun.cpp: In function 'void mySetHint(int, int, bool)':
speedrun.cpp:16:9: warning: variable 'b2' set but not used [-Wunused-but-set-variable]
16 | int b2;
| ^~
# | 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... |