이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "speedrun.h"
#include <bits/stdc++.h>
using namespace std;
bool vis[1007];
int parset[1007];
vector<int> adj[1007];
vector<int> dorder[1007];
int n;
void dfs(int x, int p, int d){
vis[x] = 1;
parset[x] = p;
dorder[d].push_back(x);
for (auto y : adj[x]){
if (!vis[y]){
dfs(y, x, d+1);
}
}
}
void assignHints(int subtask, int N, int A[], int B[]) { /* your solution here */
setHintLen(20);
for (int x = 1; x < N; x++){
adj[A[x]].push_back(B[x]);
adj[B[x]].push_back(A[x]);
}
//let root be 1 always
dfs(1, 0, 0);
vector<int> inorder;
for (int x = 0; x <= N; x++){
for (auto y : dorder[x]){
inorder.push_back(y);
}
}
//data 1 is par
//data 2 is next
int next[N+1];
for (int x = 0; x < N-1; x++){
next[ inorder[x] ] = inorder[x+1];
}
next[inorder[N-1]] = inorder[0];
//encryption
for (int x = 1; x <= N; x++){
for (int z = 0; z <= 9; z++){
if (parset[x] & (1<<z)){
setHint(x, z+1, 1);
}
}
for (int z = 0; z <= 9; z++){
if (next[x] & (1<<z)){
setHint(x, z+11, 1);
}
}
}
return;
}
int par[1007];
int nextt[1007];
int cur;
#define WEIRD -23145
void setDetails(){
if (nextt[cur] != WEIRD) return;
par[cur] = 0; nextt[cur] = 0;
for (int z = 0; z <= 9; z++){
if (getHint(z+1)){
par[cur] += (1<<z);
}
}
for (int z = 0; z <= 9; z++){
if (getHint(z+11)){
nextt[cur] += (1<<z);
}
}
}
inline void assertGoTo(int x){
goTo(x);
}
inline void returnToRoot(){
setDetails();
int steps = 0;
while (cur != 1){
assertGoTo(par[cur]);
cur = par[cur];
setDetails();
}
}
vector<int> moves[1007];
inline void trace(int x){
returnToRoot();
for (auto z : moves[x]){
assertGoTo(z);
cur = z;
}
return;
}
void speedrun(int subtask, int N, int start) { /* your solution here */
cur = start;
for (int x = 0; x <= N+3; x++) par[x] = WEIRD;
for (int x = 0; x <= N+3; x++) nextt[x] = WEIRD;
returnToRoot();
vector<int> inorder;
inorder.push_back(1);
int ptr = 0;
int nodeCount = 1;
int rounds = 0;
while (nodeCount < N){
int nextnode = nextt[inorder.back()];
rounds++;
if (rounds >= 2500) assert(false);
if (nextnode == 0) break;
trace(inorder[ptr]);
if (goTo(nextnode)){
nodeCount++;
inorder.push_back(nextnode);
cur = nextnode;
moves[cur] = moves[inorder[ptr]];
moves[cur].push_back(cur);
setDetails();
}
else{
ptr++;
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
speedrun.cpp: In function 'void returnToRoot()':
speedrun.cpp:99:6: warning: unused variable 'steps' [-Wunused-variable]
99 | int steps = 0;
| ^~~~~
# | 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... |