Submission #259708

#TimeUsernameProblemLanguageResultExecution timeMemory
259708arnold518Snowy Roads (JOI16_snowy)C++14
100 / 100
24 ms2128 KiB
#include "Anyalib.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; static const int MAXN = 500; static int N; static vector<pii> adj[MAXN+10]; static pii E[MAXN+10]; static int C[MAXN+10], A[MAXN+10], B[MAXN+10], H[MAXN+10], par[MAXN+10]; static void dfs(int now, int bef, int d) { A[now]=d; par[now]=bef; H[now]=0; for(auto nxt : adj[now]) { if(nxt.first==bef) continue; dfs(nxt.first, now, d+C[nxt.second]); H[now]=max(H[now], H[nxt.first]); } H[now]++; H[now]%=12; } void InitAnya(int _N, int A[], int B[]) { N=_N; for(int i=1; i<N; i++) { int u=A[i-1]+1, v=B[i-1]+1; adj[u].push_back({v, i}); adj[v].push_back({u, i}); E[i]={u, v}; } dfs(1, 1, 0); for(int i=1; i<N; i++) if(par[E[i].first]==E[i].second) swap(E[i].first, E[i].second); } void Anya(int _C[]) { for(int i=1; i<N; i++) { C[i]=_C[i-1]; B[E[i].second]=C[i]; } dfs(1, 1, 0); for(int i=2; i<=N; i++) Save(i-2, B[i]); int cnt=0; for(int i=1; i<=N; i++) { if(H[i]) continue; for(int j=0; j<9; j++) { if(A[i]&(1<<j)) Save(N-1+cnt*9+j, 1); else Save(N-1+cnt*9+j, 0); } cnt++; } }
#include "Borislib.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; static const int MAXN = 500; static int N; static vector<pii> adj[MAXN+10]; static pii E[MAXN+10]; static int C[MAXN+10], A[MAXN+10], B[MAXN+10], H[MAXN+10], par[MAXN+10]; static void dfs(int now, int bef, int d) { A[now]=d; par[now]=bef; for(auto nxt : adj[now]) { if(nxt.first==bef) continue; dfs(nxt.first, now, d+C[nxt.second]); H[now]=max(H[now], H[nxt.first]); } H[now]++; H[now]%=12; } void InitBoris(int _N, int A[], int B[]) { N=_N; for(int i=1; i<N; i++) { int u=A[i-1]+1, v=B[i-1]+1; adj[u].push_back({v, i}); adj[v].push_back({u, i}); E[i]={u, v}; } dfs(1, 1, 0); int cnt=0; for(int i=1; i<=N; i++) if(H[i]==0) B[i]=cnt++; } int Boris(int city) { city++; int ret=0; int cnt=0; for(int i=1; i<=N; i++) if(H[i]==0) B[i]=cnt++; while(city!=1) { if(H[city]==0) { int t=0; for(int i=0; i<9; i++) t+=(Ask(N-1+B[city]*9+i)<<i); ret+=t; break; } else { int t=Ask(city-2); ret+=t; city=par[city]; } } return ret; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...