#include <bits/stdc++.h>
#ifdef MINA
#include "grader.cpp"
#endif
#include "speedrun.h"
using namespace std;
typedef int64_t ll;
bool get(int vals[4]) {
if (~vals[0]) return 1;
for (int j = 0; j < 4; j++) {
vals[j] = 0;
for (int b = 0; b < 10; b++) {
if (getHint(10 * j + b + 1)) {
vals[j] |= 1 << b;
}
}
}
return 1;
}
void assign(int i, int vals[4]) {
for (int j = 0; j < 4; j++) {
for (int b = 0; b < 10; b++) {
if ((vals[j] >> b) & 1) {
setHint(i, 10 * j + b + 1, 1);
}
}
}
}
void dfs(int i, int par, int prv, int nxt, vector<int> adj[], int vals[][4]) {
vals[i][0] = 0;
vals[i][1] = prv;
vals[i][2] = nxt;
vals[i][3] = par;
for (int j = 0; j < adj[i].size(); j++) {
if (adj[i][j] == par) continue;
vals[i][0] = adj[i][j];
int newpar = i;
int newprv = 0;
int newnxt = 0;
for (int k = j - 1; k >= 0; k--) {
if (adj[i][k] == par) continue;
newprv = adj[i][k];
break;
}
for (int k = j + 1; k < adj[i].size(); k++) {
if (adj[i][k] == par) continue;
newnxt = adj[i][k];
break;
}
dfs(adj[i][j], newpar, newprv, newnxt, adj, vals);
}
}
void assignHints(int subtask, int n, int a[], int b[]) {
vector<int> adj[n + 1];
for (int i = 1; i < n; i++) {
adj[a[i]].push_back(b[i]);
adj[b[i]].push_back(a[i]);
}
setHintLen(40);
int vals[n + 1][4];
memset(vals, -1, sizeof vals);
dfs(1, 0, 0, 0, adj, vals);
for (int i = 1; i <= n; i++) {
assign(i, vals[i]);
}
}
void dfs(int i, int vals[][4]) {
while (1) {
get(vals[i]);
if (vals[i][0]) {
goTo(vals[i][0]);
dfs(vals[i][0], vals);
}
if (vals[i][1]) {
goTo(vals[i][3]);
goTo(vals[i][1]);
i = vals[i][1];
} else {
break;
}
}
get(vals[i]);
if (vals[i][3]) goTo(vals[i][3]);
}
void speedrun(int subtask, int n, int start) {
int vals[n + 1][4];
memset(vals, -1, sizeof vals);
int cur = start;
while (get(vals[cur]) && vals[cur][3]) {
cur = vals[cur][3];
goTo(cur);
}
assert(cur == 1);
dfs(cur, vals);
}
Compilation message
speedrun.cpp: In function 'void dfs(int, int, int, int, std::vector<int>*, int (*)[4])':
speedrun.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int j = 0; j < adj[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~
speedrun.cpp:46:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (int k = j + 1; k < adj[i].size(); k++) {
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
1644 KB |
Output is correct |
2 |
Correct |
73 ms |
1392 KB |
Output is correct |
3 |
Correct |
56 ms |
1404 KB |
Output is correct |
4 |
Correct |
67 ms |
1640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
The length is too large |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
The length is too large |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
1404 KB |
Output is correct |
2 |
Correct |
63 ms |
1388 KB |
Output is correct |
3 |
Correct |
67 ms |
1304 KB |
Output is correct |
4 |
Correct |
59 ms |
1408 KB |
Output is correct |
5 |
Correct |
59 ms |
1388 KB |
Output is correct |
6 |
Correct |
72 ms |
1292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
58 ms |
1388 KB |
Partial solution |
2 |
Partially correct |
60 ms |
1160 KB |
Partial solution |
3 |
Partially correct |
77 ms |
1352 KB |
Partial solution |
4 |
Partially correct |
56 ms |
1904 KB |
Partial solution |
5 |
Partially correct |
72 ms |
1392 KB |
Partial solution |
6 |
Partially correct |
66 ms |
1404 KB |
Partial solution |
7 |
Partially correct |
64 ms |
1652 KB |
Partial solution |