Submission #645534

#TimeUsernameProblemLanguageResultExecution timeMemory
645534TimDeeSpeedrun (RMI21_speedrun)C++17
48 / 100
441 ms8768 KiB
#include "speedrun.h" #include <bits/stdc++.h> using namespace std; vector<int> p(1e3+1); vector<int> r(1e3+1,0); int get(int a) { return (a==p[a])?a:get(a); } void uni(int a, int b) { a=get(a), b=get(b); if (a==b) return; if (r[a]==r[b]) ++r[a]; if (r[a]<r[b]) swap(a,b); p[b]=a; } void assignHints(int id,int n, int a[], int b[]) { if (id==1) { setHintLen(n); for(int i=1;i<=n-1;++i) { int u=a[i],v=b[i]; setHint(u,v,1); setHint(v,u,1); } } 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)))); } } } 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)))); } } } if (id==4) { setHintLen(316); vector<vector<int>> adj(n+1); for (int i=1; i<n; ++i) { adj[a[i]].push_back(b[i]); adj[b[i]].push_back(a[i]); } vector<pair<int,int>> toadd; for (int i=1; i<=n; ++i) { int s=adj[i].size(); for (int j=10; j; --j) setHint(i,j,!!(s&(1<<(j-1)))); int pt=10; for (auto x:adj[i]) { if (pt<306) { for (int j=10; j; --j) setHint(i,j+pt,!!(x&(1<<(j-1)))); pt+=10; } else { toadd.push_back({i,x}); } } for (; pt<296; pt+=20) { if (toadd.empty()) break; auto p=toadd.back(); toadd.pop_back(); for (int j=10; j; --j) { setHint(i,j+pt,!!(p.first&(1<<(j-1)))); setHint(i,j+pt+10,!!(p.second&(1<<(j-1)))); } } } } } int n; vector<vector<int>> adj(1e3+1,vector<int>(1e3+1,0)); vector<int> vis(1e3+1,0); void dfs(int u, int p) { for (int j=1; j<=n; ++j) { adj[u][j]=getHint(j); } for (int i=1; i<=n; ++i) { if (i==p) continue; if (adj[u][i]) { goTo(i); dfs(i,u); } } if (p==-1) return; goTo(p); } void dfs2(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); dfs2(i,u); } } if (p==-1) return; goTo(p); } void scuza(int u, int p) { vis[u]=1; int sz=0; for (int j=10; j>0; --j) { sz+=getHint(j)<<(j-1); } int pt=10; for (;pt<=min(sz*10,306);pt+=10) { int x=0; for (int j=10; j; --j) x+=getHint(j+pt)<<(j-1); adj[u][x]=1; adj[x][u]=1; } for (int j=1; j<=n; ++j) { if (j==p) continue; if (vis[j]) continue; if (adj[u][j]) { goTo(j); scuza(j,u); } } if (p==-1) return; if (sz<=30) { goTo(p); return; } for (int j=1; j<=n; ++j) { if (j==p) continue; if (vis[j]) continue; if (adj[u][j]) { goTo(j); scuza(j,u); } } for (int j=1; j<=n; ++j) { if (j==p) continue; if (vis[j]) continue; int x=goTo(j); if (x) scuza(j,u); } } int center=0; void speedrun(int id,int N,int start) { for (int i=1; i<=1e3; ++i) p[i]=i; n=N; if (id==1) { dfs(start,-1); } 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); } } if (id==3) { dfs2(start,-1); } if (id==4) { scuza(start,-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...