#include <bits/stdc++.h>
#ifdef MINA
#include "grader.cpp"
#endif
#include "speedrun.h"
using namespace std;
typedef int64_t ll;
// {child, next, par}
bool get(int vals[3]) {
if (~vals[0]) return 1;
for (int j = 0; j < 3; 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[3]) {
for (int j = 0; j < 3; j++) {
for (int b = 0; b < 10; b++) {
if ((vals[j] >> b) & 1) {
setHint(i, 10 * j + b + 1, 1);
}
}
}
}
// {child, nxt, par}
void dfs(int i, int par, int nxt, vector<int> adj[], int vals[][3]) {
vals[i][0] = 0;
vals[i][1] = nxt;
vals[i][2] = par;
for (int j = 0; j < (int) adj[i].size(); j++) {
if (adj[i][j] == par) continue;
if (!vals[i][0]) {
vals[i][0] = adj[i][j];
}
int newpar = i;
int newnxt = 0;
for (int k = j + 1; k < (int) adj[i].size(); k++) {
if (adj[i][k] == par) continue;
newnxt = adj[i][k];
break;
}
dfs(adj[i][j], newpar, newnxt, adj, vals);
}
}
void assignHints(int subtask, int n, int a[], int b[]) {
if (subtask == 2) {
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(11);
for (int i = 1; i <= n; i++) {
if (adj[i].size() == 1) {
int v = adj[i][0];
for (int b = 0; b < 10; b++) {
if ((v >> b) & 1) {
setHint(i, b + 1, 1);
}
}
} else {
setHint(i, 11, 1);
}
}
return;
} else if (subtask == 3) {
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(20);
for (int i = 1; i <= n; i++) {
for (int j = 0; j < adj[i].size(); j++) {
int v = adj[i][j];
for (int b = 0; b < 10; b++) {
if ((v >> b) & 1) {
setHint(i, 10 * j + b + 1, 1);
}
}
}
}
return;
}
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(30);
int vals[n + 1][3];
memset(vals, -1, sizeof vals);
dfs(1, 0, 0, adj, vals);
for (int i = 1; i <= n; i++) {
assign(i, vals[i]);
}
}
// {child, next, par}
void dfs(int i, int vals[][3]) {
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][2]);
goTo(vals[i][1]);
i = vals[i][1];
} else {
break;
}
}
get(vals[i]);
if (vals[i][2]) goTo(vals[i][2]);
}
void dfs2(int i, int par, int n) {
if (getHint(11)) {
for (int nxt = 1; nxt <= n; nxt++) {
if (nxt == par || nxt == i) continue;
goTo(nxt);
dfs2(nxt, i, n);
}
if (par) goTo(par);
} else {
int nxt = 0;
for (int b = 0; b < 10; b++) {
if (getHint(b + 1)) nxt |= 1 << b;
}
goTo(nxt);
if (nxt != par) {
dfs2(nxt, i, n);
}
}
}
void dfs3(int i, int par, int n) {
for (int j = 0; j < 2; j++) {
int v = 0;
for (int b = 0; b < 10; b++) {
if (getHint(10 * j + b + 1)) {
v |= 1 << b;
}
}
if (v && v != par) {
goTo(v);
dfs3(v, i, n);
}
}
if (par) goTo(par);
}
void speedrun(int subtask, int n, int start) {
if (subtask == 2) {
dfs2(start, 0, n);
return;
} else if (subtask == 3) {
dfs3(start, 0, n);
return;
}
int vals[n + 1][3];
memset(vals, -1, sizeof vals);
int cur = start;
while (get(vals[cur]) && vals[cur][2]) {
cur = vals[cur][2];
goTo(cur);
}
assert(cur == 1);
dfs(cur, vals);
}
Compilation message
speedrun.cpp: In function 'void assignHints(int, int, int*, int*)':
speedrun.cpp:80:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for (int j = 0; j < adj[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
1644 KB |
Output is correct |
2 |
Correct |
45 ms |
1644 KB |
Output is correct |
3 |
Correct |
49 ms |
1156 KB |
Output is correct |
4 |
Correct |
55 ms |
1400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
1128 KB |
Output is correct |
2 |
Correct |
20 ms |
1072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
940 KB |
Output is correct |
2 |
Correct |
54 ms |
1356 KB |
Output is correct |
3 |
Correct |
46 ms |
1196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
1796 KB |
Output is correct |
2 |
Correct |
52 ms |
1644 KB |
Output is correct |
3 |
Correct |
47 ms |
1016 KB |
Output is correct |
4 |
Correct |
52 ms |
1548 KB |
Output is correct |
5 |
Correct |
52 ms |
1648 KB |
Output is correct |
6 |
Correct |
46 ms |
1664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
54 ms |
1896 KB |
Partial solution |
2 |
Partially correct |
56 ms |
1392 KB |
Partial solution |
3 |
Partially correct |
52 ms |
1644 KB |
Partial solution |
4 |
Partially correct |
55 ms |
1652 KB |
Partial solution |
5 |
Partially correct |
42 ms |
1656 KB |
Partial solution |
6 |
Partially correct |
47 ms |
2164 KB |
Partial solution |
7 |
Partially correct |
50 ms |
1388 KB |
Partial solution |