#include <bits/stdc++.h>
#include "speedrun.h"
using namespace std;
void dfsHint(int curr, int par, vector<vector<int>> &adjHint, vector<int> &path)
{
path.push_back(curr);
for(int i = 0; i < 10; i++) // set in big-endian
{
if(par & (1 << i)) setHint(curr, i + 1, 1);
else setHint(curr, i + 1, 0);
}
for(int next : adjHint[curr])
{
if(next == par) continue;
dfsHint(next, curr, adjHint, path);
}
}
void assignHints(int subtask, int N, int A[], int B[])
{
setHintLen(20);
vector<vector<int>> adjHint(N + 1);
for(int i = 1; i < N; i++)
{
adjHint[A[i]].push_back(B[i]);
adjHint[B[i]].push_back(A[i]);
}
for(int i = 1; i <= N; i++) sort(adjHint[i].begin(), adjHint[i].end());
vector<int> path;
dfsHint(1, 0, adjHint, path);
// for(auto i : path) cout << i << " ";
// cout << "\n";
for(int i = 0; i < path.size() - 1; i++)
{
int child = path[i + 1];
for(int j = 10; j < 20; j++) // set in big-endian
{
if(child & (1 << (j - 10))) setHint(path[i], j + 1, 1);
else setHint(path[i], j + 1, 0);
}
}
}
int dfs(int curr, int toTry) // returns next value to try
{
int par = 0, child = 0;
for(int i = 0; i < 10; i++) par += getHint(i + 1) * (1 << i);
for(int i = 10; i < 20; i++) child += getHint(i + 1) * (1 << (i - 10));
if(toTry == 0) toTry = child;
if(toTry == 0) return 0;
while(toTry != 0 && goTo(toTry))
{
toTry = dfs(toTry, 0);
}
if(par == 0) return 0;
goTo(par);
return toTry;
}
void speedrun(int subtask, int N, int start)
{
if(N == 1) return;
int l = getLength();
while(start != 1)
{
int par = 0;
for(int i = 0; i < 10; i++) par += getHint(i + 1) * (1 << i);
goTo(par);
start = par;
}
dfs(start, 0);
}
Compilation message
speedrun.cpp: In function 'void assignHints(int, int, int*, int*)':
speedrun.cpp:35:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int i = 0; i < path.size() - 1; i++)
| ~~^~~~~~~~~~~~~~~~~
speedrun.cpp: In function 'void speedrun(int, int, int)':
speedrun.cpp:67:6: warning: unused variable 'l' [-Wunused-variable]
67 | int l = getLength();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
792 KB |
Output is correct |
2 |
Correct |
170 ms |
756 KB |
Output is correct |
3 |
Correct |
114 ms |
736 KB |
Output is correct |
4 |
Correct |
191 ms |
904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
848 KB |
Output is correct |
2 |
Correct |
148 ms |
676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
868 KB |
Output is correct |
2 |
Correct |
191 ms |
740 KB |
Output is correct |
3 |
Correct |
165 ms |
740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
189 ms |
756 KB |
Output is correct |
2 |
Correct |
141 ms |
724 KB |
Output is correct |
3 |
Correct |
173 ms |
692 KB |
Output is correct |
4 |
Correct |
183 ms |
740 KB |
Output is correct |
5 |
Correct |
166 ms |
724 KB |
Output is correct |
6 |
Correct |
201 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
138 ms |
856 KB |
Output is correct |
2 |
Correct |
201 ms |
812 KB |
Output is correct |
3 |
Correct |
191 ms |
804 KB |
Output is correct |
4 |
Correct |
180 ms |
932 KB |
Output is correct |
5 |
Correct |
139 ms |
732 KB |
Output is correct |
6 |
Correct |
208 ms |
672 KB |
Output is correct |
7 |
Correct |
183 ms |
688 KB |
Output is correct |