Submission #966990

#TimeUsernameProblemLanguageResultExecution timeMemory
966990AtabayRajabliSpeedrun (RMI21_speedrun)C++17
100 / 100
69 ms2364 KiB
#include "speedrun.h" #include <bits/stdc++.h> using namespace std; const int sz = 2005; int cnt, num, in[sz], t[sz], p[sz]; vector<int> g[sz]; void dfs(int v) { in[v] = ++cnt; t[in[v]] = v; for(int i : g[v]) { if(!in[i]) { p[i] = v; dfs(i); } } } void assignHints(int subtask, int N, int A[], int B[]) { for(int i = 1; i < N; i++) { g[A[i]].push_back(B[i]); g[B[i]].push_back(A[i]); } setHintLen(20); dfs(1); for(int i = 1; i <= N; i++) { int nxt = t[in[i] + 1]; int prv = p[i]; if(nxt == 0)nxt = 1; for(int j = 0; j < 10; j++) { if(prv & (1 << j)) setHint(i, (j + 11), 1); if(nxt & (1 << j)) setHint(i, (j + 1), 1); } } } void f(int go, int N) { if(num == N)return; int nxt = 0, prv = 0; for(int i = 0; i < 10; i++) { nxt += getHint(i + 1) * (1 << i); prv += getHint(i + 11) * (1 << i); } if(go) { if(!goTo(go)) { //cout << "could not go to " << go << ", went to " << prv << endl; goTo(prv); f(go, N); } else { num++; //cout << "went to " << go << endl; f(0, N); } } else { if(!goTo(nxt)) { goTo(prv); //cout << "could not go to " << nxt << ", went to " << prv << endl; f(nxt, N); } else { //cout << "went to " << nxt << endl; num++; f(0, N); } } } void speedrun(int subtask, int N, int start) { num = 1; f(0, N); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...