#define pi pair<int,int>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define vi vector<int>
#include "speedrun.h"
using namespace std;
void seth(int i, pi p) {
for (int j = 1; j <= 10; j++) {
setHint(i, j, p.first % 2);
p.first /= 2;
}
for (int j = 11; j <= 20; j++) {
setHint(i, j, p.second % 2);
p.second /= 2;
}
}
pi get() {
pi ans;
int j = 1;
for (int i = 1; i < 1024; i*=2) {
ans.first += getHint(j) * i;
j++;
}
for (int i = 1; i < 1024; i *= 2) {
ans.second += getHint(j) * i;
j++;
}
return ans;
}
void dfs(int i, vi&pad, vector<vi>&fr) {
for (int f : fr[i]) {
if (f != pad[i]) {
pad[f] = i;
dfs(f,pad,fr);
}
}
}
#include <queue>
void assignHints(int subtask, int N, int A[], int B[]) {
/* your solution here */
setHintLen(20);
if (N == 1)return;
vector<vi> fr(N + 1);
for (int i = 1; i < N; i++) {
fr[A[i]].push_back(B[i]);
fr[B[i]].push_back(A[i]);
}
vi pad(N + 1);
vector<vi> son(N + 1);
dfs(1, pad, fr);
for (int i = 2; i <= N; i++) {
son[pad[i]].push_back(i);
}
/*for (int i = 1; i <= N; i++) {
if (son[i].empty())son[i].push_back(0);
}*/
vi v;
queue<int> q;
q.push(1);
while (!q.empty()) {
int i = q.front();
q.pop();
v.push_back(i);
for (int f : son[i]) {
q.push(f);
}
}
v.push_back(0);
for (int i = 0; i < N; i++) {
seth(v[i], { pad[v[i]],v[i + 1] });
}/*
for (int i = 1; i <= N; i++) {
for (int j = 0; j < son[i].size(); j++) {
int s = son[i][j];
if (s == 0)break;
if (s == son[i].back()) {
seth(s, { son[s][0],i });
}
else {
seth(s, { son[s][0],son[i][j + 1] });
}
}
}
seth(1, { son[1][0],0 });*/
}
void walk(int a, int b, vi pad) {
while (a != 1) {
pi p = get();
a = p.first;
goTo(p.first);
}
vi v={b};
while (b != 1) {
v.push_back(pad[b]);
b = pad[b];
}
for (int i = v.size() - 2; i >= 0; i--) {
goTo(v[i]);
}
}
void speedrun(int subtask, int N, int start) {
if (N == 1)return;
int x = start;
while (x != 1) {
pi p = get();
x = p.first;
goTo(p.first);
}
vi v = { 1 };
int it = 0;
vi pad(N + 1);
for (int i = 0; i < N - 1; i++) {
v.push_back(get().second);
while (true) {
walk(x, v[it], pad);
x = v[it];
if (goTo(v.back())) {
x = v.back();
pad[x] = v[it];
break;
}
else it++;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
241 ms |
1220 KB |
Output is correct |
2 |
Execution timed out |
3547 ms |
1012 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
1516 KB |
Output is correct |
2 |
Correct |
121 ms |
1260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3548 ms |
1216 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
883 ms |
1220 KB |
Output is correct |
2 |
Correct |
314 ms |
1336 KB |
Output is correct |
3 |
Correct |
164 ms |
1332 KB |
Output is correct |
4 |
Correct |
3344 ms |
1216 KB |
Output is correct |
5 |
Correct |
626 ms |
972 KB |
Output is correct |
6 |
Correct |
118 ms |
1096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
621 ms |
1332 KB |
Output is correct |
2 |
Correct |
362 ms |
1216 KB |
Output is correct |
3 |
Correct |
197 ms |
1752 KB |
Output is correct |
4 |
Correct |
3216 ms |
1224 KB |
Output is correct |
5 |
Correct |
218 ms |
1236 KB |
Output is correct |
6 |
Correct |
684 ms |
1220 KB |
Output is correct |
7 |
Correct |
112 ms |
1336 KB |
Output is correct |