Submission #647491

#TimeUsernameProblemLanguageResultExecution timeMemory
647491LucaIlieSpeedrun (RMI21_speedrun)C++17
100 / 100
239 ms804 KiB
#include "speedrun.h" #include <bits/stdc++.h> using namespace std; const int maxN = 1000; const int maxLogN = 10; int parent[maxN]; vector <int> ord; vector <int> edges[maxN + 1]; void setHints( int u, int p, int v ) { for ( int b = 0; b < maxLogN; b++ ) setHint( u, b + 1, (p >> b) & 1 ); for ( int b = 0; b < maxLogN; b++ ) setHint( u, b + 1 + maxLogN, (v >> b) & 1 ); } void dfsAssignHints( int u, int p ) { parent[u] = p; ord.push_back( u ); for ( auto v: edges[u] ) { if ( v != p ) dfsAssignHints( v, u ); } } void assignHints( int subtask, int n, int a[], int b[] ) { for ( int i = 1; i <= n - 1; i++ ) { edges[a[i]].push_back( b[i] ); edges[b[i]].push_back( a[i] ); } setHintLen( 2 * maxLogN ); dfsAssignHints( 1, 0 ); for ( int i = 0; i < n; i++ ) setHints( ord[i], parent[ord[i]], (i < n - 1 ? ord[i + 1] : 0) ); } bool visited[maxN + 1]; int getParent() { int p = 0; for ( int b = 0; b < maxLogN; b++ ) p += (getHint( b + 1 ) << b); return p; } int getNextOrd() { int v; v = 0; for ( int b = 0; b < maxLogN; b++ ) v += (getHint( b + 1 + maxLogN ) << b); return v; } void speedrun( int subtask, int n, int start ) { int u = start, p = getParent(); while ( p != 0 ) { u = p; goTo( u ); p = getParent(); } u = getNextOrd(); while ( u != 0 ) { while ( !goTo( u ) ) { p = getParent(); goTo( p ); } u = getNextOrd(); } }
#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...