#include "speedrun.h"
#include <bits/stdc++.h>
//~ #include <ext/pb_ds/assoc_container.hpp>
//~ using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
//~ typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) ll((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
const int MAXN = 1e3+7;
vector <int> graph[MAXN];
int parent[MAXN];
vector <int> stacc, used(MAXN);
int n;
int len;
void set_to_child(int from, int to) {
for (int bit = 0; bit < 10; bit++) {
if (to & (1 << bit)) {
setHint(from, bit+1, 1);
}
else {
setHint(from, bit+1, 0);
}
}
}
void set_to_parent(int from, int to) {
for (int bit = 0; bit < 10; bit++) {
if (to & (1 << bit)) {
setHint(from, bit+11, 1);
}
else {
setHint(from, bit+11, 0);
}
}
}
void set_dfs(int v, int p = 0) {
if (used[v]) {
return;
}
parent[v] = p;
used[v] = 1;
stacc.pb(v);
for (auto to : graph[v]) {
set_dfs(to, v);
}
}
void assignHints(int subtask, int N, int A[], int B[]) { /* your solution here */
setHintLen(20);
n = N;
for (int i = 1; i < n; i++) {
graph[A[i]].pb(B[i]);
graph[B[i]].pb(A[i]);
}
set_dfs(1);
for (int i = 0; i < sz(stacc); i++) {
set_to_child(stacc[i], stacc[(i+1)%n]);
set_to_parent(stacc[i], parent[stacc[i]]);
}
}
int get_child() {
int res = 0;
for (int bit = 0; bit < 10; bit++) {
if (getHint(bit+1)) {
res += (1 << bit);
}
}
return res;
}
int get_parent() {
int res = 0;
for (int bit = 0; bit < 10; bit++) {
if (getHint(bit+11)) {
res += (1 << bit);
}
}
return res;
}
/*
5
1 2
2 3
3 4
3 5
2
*/
void speedrun(int subtask, int N, int start) { /* your solution here */
len = getLength();
set <int> st;
while (start != 1) {
start = get_parent();
goTo(get_parent());
}
int nxt = 0;
while (sz(st) < N) {
st.insert(start);
if (nxt) {
while (!goTo(nxt)) {
goTo(get_parent());
}
start = nxt;
nxt = 0;
}
else {
auto ch = get_child();
if (!goTo(ch)) {
nxt = ch;
}
else {
start = ch;
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
190 ms |
656 KB |
Output is correct |
2 |
Correct |
204 ms |
660 KB |
Output is correct |
3 |
Correct |
213 ms |
676 KB |
Output is correct |
4 |
Correct |
227 ms |
908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
197 ms |
712 KB |
Output is correct |
2 |
Correct |
189 ms |
784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
174 ms |
660 KB |
Output is correct |
2 |
Correct |
214 ms |
660 KB |
Output is correct |
3 |
Correct |
183 ms |
660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
177 ms |
704 KB |
Output is correct |
2 |
Correct |
170 ms |
676 KB |
Output is correct |
3 |
Correct |
210 ms |
648 KB |
Output is correct |
4 |
Correct |
178 ms |
832 KB |
Output is correct |
5 |
Correct |
206 ms |
788 KB |
Output is correct |
6 |
Correct |
186 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
231 ms |
656 KB |
Output is correct |
2 |
Correct |
187 ms |
676 KB |
Output is correct |
3 |
Correct |
231 ms |
920 KB |
Output is correct |
4 |
Correct |
175 ms |
660 KB |
Output is correct |
5 |
Correct |
174 ms |
796 KB |
Output is correct |
6 |
Correct |
158 ms |
716 KB |
Output is correct |
7 |
Correct |
167 ms |
868 KB |
Output is correct |