Submission #745643

#TimeUsernameProblemLanguageResultExecution timeMemory
745643Username4132Rail (IOI14_rail)C++14
30 / 100
306 ms98820 KiB
#include "rail.h" #include<iostream> #include<vector> using namespace std; using pii = pair<int, int>; #define forn(i, n) for(int i=0; i<(int)n; ++i) #define forsn(i, s, n) for(int i=s; i<(int)n; ++i) #define PB push_back #define F first #define S second const int MAXN=5010, INF=1000000010; int *rel, *res, count, le, ri; int n, dis[MAXN][MAXN]; bool vis[MAXN]; vector<pii> g[MAXN]; void dfs(int v){ vis[v]=true, ++count; for(pii to:g[v]) if(!vis[to.F]){ if(res[v]==1) rel[to.F]=rel[v]+to.S; else rel[to.F]=rel[v]-to.S; if(rel[le]>rel[to.F]) le=to.F; if(rel[ri]<rel[to.F]) ri=to.F; res[to.F] = res[v]==1? 2 : 1; dfs(to.F); } } void findLocation(int N, int first, int location[], int stype[]) { n=N; forn(i, n) forsn(j, i, n) dis[i][j]=dis[j][i]=getDistance(i, j); forn(i, n){ int mn=INF, ind=-1; forn(j, n) if(j!=i && mn>dis[i][j]) mn=dis[i][j], ind=j; g[i].PB({ind, mn}), g[ind].PB({i, mn}); } rel=location, res=stype; rel[0]=first, res[0]=1; dfs(0); while(count!=n){ int mn=INF, ind=-1, type=-1, coord=-1; forn(i, n) if(!vis[i]){ if(mn>dis[le][i]) mn=dis[le][i], type=2, coord=rel[le]+mn, ind=i; if(mn>dis[ri][i]) mn=dis[ri][i], type=1, coord=rel[ri]-mn, ind=i; } rel[ind]=coord, stype[ind]=type; dfs(ind); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...