#include <bits/stdc++.h>
using namespace std;
#include "speedrun.h"
using vi = vector<int>;
using vvi = vector<vi>;
#define pb push_back
void fset(int x, int pos, int val){
int y = 1;
if (pos) y += 10;
for (int c = 0; c < 10; c++){
setHint(x, y+c, (bool)((val >> (9 - c)) & 1));
}
}
int fget(int pos){
int y = 1;
if (pos) y += 10;
int res = 0;
for (int c = 0; c < 10; c++){
res = res * 2 + (int)(getHint(y+c));
}
return res;
}
vvi adj;
vi dfsorder, parent;
void dfs(int x, int p = -1){
dfsorder.pb(x);
parent[x] = (p < 0 ? 1022 : p);
for (auto k: adj[x]){
if (k - p){
dfs(k, x);
}
}
}
void assignHints(int subtask, int N, int a[], int b[]){
// cout << "*\n";
setHintLen(20);
adj.assign(N+1, vi());
for (int i=1; i<N; i++){
adj[a[i] - 1].pb(b[i] - 1);
adj[b[i] - 1].pb(a[i] - 1);
}
parent.assign(N+1, 1022);
dfs(0);
// cout << "DEBUG: [";
// for (int i=0; i<N; i++) cout << parent[i] << ", ";
// cout << "]\n";
for (int i=0; i<N; i++){
fset(i+1, 0, parent[i] + 1);
}
for (int i=0; i<(int)dfsorder.size()-1; i++){
fset(dfsorder[i] + 1, 1, dfsorder[i] + 1);
}
}
void speedrun(int subtask, int N, int start){
// getLength() = 20
// cout << "*\n";
int c = start;
int p = fget(0);
while (p < 1020){
// cout << "p = " << p << "\n";
goTo(p);
// cout << "Here\n";
c = p;
// cout << "Here2\n";
p = fget(0);
// cout << "Here3\n";
}
// at root
vi r(N+1, 0); int sm = 1;
r[c] = 1;
// int debug = 0;
// while ((sm < N) && (debug < 10)){
while (sm < N){
// cout << "DEBUG: [";
// for (int i=1; i<=N; i++) cout << r[i] << ", ";
// cout << "]\n";
int val = fget(1);
bool test = goTo(val);
// cout << val << " " << test << "\n";
while (!test){
goTo(fget(0));
test = goTo(val);
}
c = val;
sm -= r[c];
r[c] = 1;
sm++;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
96 ms |
660 KB |
Invalid node index to goTo |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
173 ms |
668 KB |
Invalid node index to goTo |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
218 ms |
816 KB |
Invalid node index to goTo |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
159 ms |
728 KB |
Invalid node index to goTo |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
158 ms |
720 KB |
Invalid node index to goTo |
2 |
Halted |
0 ms |
0 KB |
- |