#include "speedrun.h"
#include <cstdio>
#include <vector>
using namespace std;
int n, center;
vector<int> adj[1006];
bool visited[1006];
void assign(int x, int y, int z) {
for (int i = 0; i < 10; i++) setHint(x + 1, y * 10 + i + 1, z & 1 << i ? true : false);
}
int get(int y) {
int ret = 0;
for (int i = 0; i < 10; i++) ret |= getHint(y * 10 + i + 1) << i;
return ret;
}
void move(int x) {
visited[x] = true;
goTo(x + 1);
}
void _dfs(int x, int prev = -1) {
if (prev == -1) assign(x, 2, 1023);
else assign(x, 2, prev);
int pv = -1;
for (auto &i: adj[x]) if (i != prev) {
if (pv == -1) assign(x, 0, i);
else assign(pv, 1, i);
pv = i;
_dfs(i, x);
}
if (pv == -1) assign(x, 0, 1023);
else assign(pv, 1, x);
}
void assignHints(int subtask, int n, int a[], int b[]) {
if (subtask == 2) {
::n = n;
for (int i = 1; i < n; i++) {
adj[a[i] - 1].push_back(b[i] - 1);
adj[b[i] - 1].push_back(a[i] - 1);
}
setHintLen(20);
if (n == 1) return;
for (int i = 0; i < n; i++) if ((int)adj[i].size() != 1) center = i;
for (int i = 0; i < n; i++) assign(i, 0, center);
assign(center, 1, adj[center][0]);
for (int i = 0; i < (int)adj[center].size(); i++) assign(adj[center][i], 1, adj[center][(i + 1) % (int)adj[center].size()]);
return;
}
if (subtask == 3) {
::n = n;
for (int i = 1; i < n; i++) {
adj[a[i] - 1].push_back(b[i] - 1);
adj[b[i] - 1].push_back(a[i] - 1);
}
setHintLen(20);
for (int i = 0; i < n; i++) for (int j = 0; j < 2; j++) {
if (j < (int)adj[i].size()) assign(i, j, adj[i][j]);
else assign(i, j, 1023);
}
return;
}
::n = n;
for (int i = 1; i < n; i++) {
adj[a[i] - 1].push_back(b[i] - 1);
adj[b[i] - 1].push_back(a[i] - 1);
}
setHintLen(30);
assign(0, 1, 1023);
_dfs(0);
}
void connect(int x, int y) {
adj[x].push_back(y);
adj[y].push_back(x);
}
void dfs(int x, int prev = -1) {
visited[x] = true;
if (get(0) != 1023) connect(x, get(0));
if (get(2) != 1023) connect(x, get(2));
if (get(2) != 1023 && get(1) != 1023) connect(get(1), get(2));
for (int i = 0; i < (int)adj[x].size(); i++) if (adj[x][i] != prev && !visited[adj[x][i]]) {
goTo(adj[x][i] + 1);
dfs(adj[x][i], x);
goTo(x + 1);
}
}
bool notVisited() {
for (int i = 0; i < n; i++) if (!visited[i]) return true;
return false;
}
void dfs3(int x, int prev = -1) {
for (int i = 0; i < 2; i++) if (get(i) != 1023) adj[x].push_back(get(i));
for (auto &i: adj[x]) if (i != prev) {
goTo(i + 1);
dfs3(i, x);
}
if (prev != -1) goTo(prev + 1);
}
void speedrun(int subtask, int n, int st) {
if (subtask == 2) {
::n = n;
if (n == 1) return;
st--;
visited[st] = true;
while (notVisited()) {
int a = get(0), b = get(1);
if (visited[b]) move(a);
else move(a), move(b);
}
return;
}
if (subtask == 3) {
::n = n;
dfs3(st - 1);
return;
}
::n = n;
dfs(st - 1);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
212 ms |
736 KB |
Output is correct |
2 |
Correct |
307 ms |
988 KB |
Output is correct |
3 |
Correct |
305 ms |
684 KB |
Output is correct |
4 |
Correct |
216 ms |
772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
168 ms |
672 KB |
Output is correct |
2 |
Correct |
143 ms |
708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
181 ms |
828 KB |
Output is correct |
2 |
Correct |
207 ms |
792 KB |
Output is correct |
3 |
Correct |
217 ms |
800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
252 ms |
752 KB |
Output is correct |
2 |
Correct |
201 ms |
792 KB |
Output is correct |
3 |
Correct |
249 ms |
728 KB |
Output is correct |
4 |
Correct |
264 ms |
672 KB |
Output is correct |
5 |
Correct |
143 ms |
708 KB |
Output is correct |
6 |
Correct |
288 ms |
712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
288 ms |
672 KB |
Partial solution |
2 |
Partially correct |
331 ms |
672 KB |
Partial solution |
3 |
Partially correct |
300 ms |
732 KB |
Partial solution |
4 |
Partially correct |
215 ms |
736 KB |
Partial solution |
5 |
Partially correct |
203 ms |
708 KB |
Partial solution |
6 |
Partially correct |
311 ms |
796 KB |
Partial solution |
7 |
Partially correct |
189 ms |
672 KB |
Partial solution |