Submission #645568

#TimeUsernameProblemLanguageResultExecution timeMemory
645568TimDeeSpeedrun (RMI21_speedrun)C++17
63 / 100
312 ms852 KiB
#include "speedrun.h" #include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); vector<vector<int>> adj(1e3+1); vector<int> p(1e3+1,0); void dfs(int u, int P) { for (auto v:adj[u]) { if (v==P) continue; p[v]=u; dfs(v,u); } } vector<pair<int,int>> toadd; vector<pair<int,int>> edgeto(1e3+1); void dfs2(int u, int P) { int cnt=0; for (auto v:adj[u]) { if (v==P) continue; if (cnt==0) { for (int j=10; j; --j) { setHint(u,j+10,!!(u&(1<<(j-1)))); setHint(u,j+20,!!(v&(1<<(j-1)))); } edgeto[u]={u,v}; ++cnt; } else { toadd.push_back({u,v}); } } if (cnt==0) { //cout<<u<<' '<<P<<": "; //for (auto x:toadd) cout<<x.first<<' '<<x.second<<" "; //cout<<'\n'; if (toadd.size()==0) return; auto k=toadd.back(); toadd.pop_back(); for (int j=10; j; --j) { setHint(u,j+10,!!(k.first&(1<<(j-1)))); setHint(u,j+20,!!(k.second&(1<<(j-1)))); } edgeto[u]={k.first,k.second}; } dfs2(edgeto[u].second,edgeto[u].first); } void assignHints(int id,int n, int a[], int b[]) { for (int i=1; i<n; ++i) { adj[a[i]].push_back(b[i]); adj[b[i]].push_back(a[i]); } dfs(1,0); setHintLen(30); for (int i=1; i<=n; ++i) { for (int j=10; j; --j) { setHint(i,j,!!(p[i]&(1<<(j-1)))); } } dfs2(1,0); } vector<int> par(1e3+1,0); int n; void climb(int u, int need) { int p=0; for (int j=10; j; --j) p+=getHint(j)<<(j-1); if (p==need) return; par[u]=p; goTo(p); climb(u,need); } void visit(int u) { int x=0, y=0; int p=0; for (int j=10; j; --j) p+=getHint(j)<<(j-1); par[u]=p; for (int j=10; j; --j) x+=getHint(j+10)<<(j-1); for (int j=10; j; --j) y+=getHint(j+20)<<(j-1); par[y]=x; //cout<<u<<' '<<par[u]<<' '<<x<<' '<<y<<'\n'; //int k; cin>>k; //if (k==-1) exit(0); if (x==y && y==0) return; if (u!=x) climb(u,par[x]); goTo(y); visit(y); } void speedrun(int id,int N,int start) { n=N; climb(start,0); visit(1); }
#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...