Submission #645570

#TimeUsernameProblemLanguageResultExecution timeMemory
645570TimDeeSpeedrun (RMI21_speedrun)C++17
71 / 100
299 ms984 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[]) { if (id==2) { setHintLen(20); vector<int>deg(n+1,0); for(int i=0;i<n-1;++i) deg[a[i]]++; for(int i=0;i<n-1;++i) deg[b[i]]++; int mx=0; for(int i=1;i<=n;++i) if (deg[i]>deg[mx]) mx=i; for (int i=1; i<=n; ++i) { if (i==mx) setHint(i,20,1); for (int j=11; j>0; --j) { setHint(i,j,!!(mx&(1<<(j-1)))); } } return; } if (id==3) { setHintLen(20); vector<pair<int,int>> adj(n+1,{0,0}); for (int i=1; i<n; ++i) { if (adj[a[i]].first) adj[a[i]].second=b[i]; else adj[a[i]].first=b[i]; if (adj[b[i]].first) adj[b[i]].second=a[i]; else adj[b[i]].first=a[i]; } for (int i=1; i<=n; ++i) { for (int j=10; j; --j) { setHint(i,j,!!(adj[i].first&(1<<(j-1)))); } for (int j=10; j; --j) { setHint(i,j+10,!!(adj[i].second&(1<<(j-1)))); } } return; } 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); } int center=0; void dfs22(int u, int p) { int l=0, r=0; for (int j=10; j>0; --j) { l+=getHint(j)<<(j-1); r+=getHint(j+10)<<(j-1); } adj[u][l]=1, adj[u][r]=1; for (int i=1; i<=n; ++i) { if (i==p) continue; if (adj[u][i]) { goTo(i); dfs22(i,u); } } if (p==-1) return; goTo(p); } void speedrun(int id,int N,int start) { n=N; if (id==2) { for (int j=11; j>0; --j) { center+=getHint(j)<<(j-1); } bool b=getHint(20); if (!b) { goTo(center); } for (int i=1; i<=n; ++i) { if (i==center) continue; goTo(i); goTo(center); } return; } if (id==3) { dfs22(start,-1); return; } 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...