Submission #1135457

#TimeUsernameProblemLanguageResultExecution timeMemory
1135457irmuunRail (IOI14_rail)C++20
0 / 100
216 ms98608 KiB
#include<bits/stdc++.h> #include "rail.h" using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define all(s) s.begin(),s.end() #define rall(s) s.rbegin(),s.rend() void findLocation(int N, int first, int location[], int stype[]){ location[0]=first; stype[0]=1; if(N==1){ return; } int dist[N][N]; for(int i=0;i<N;i++){ dist[i][i]=0; for(int j=i+1;j<N;j++){ dist[i][j]=getDistance(i,j); dist[j][i]=dist[i][j]; } } vector<int>g[N]; vector<pair<int,int>>v; for(int i=0;i<N;i++){ int mn=1e9,idx=0; for(int j=0;j<N;j++){ if(j==i) continue; if(dist[i][j]<mn){ mn=dist[i][j]; idx=j; } } g[i].pb(idx); g[idx].pb(i); v.pb({i,idx}); } int D=-1; for(auto [x,y]:v){ if(x==0||y==0){ if(x==0){ D=y; } if(x!=0) swap(x,y); location[x]=first+dist[x][y]; stype[x]=2; } } vector<bool>used(N); queue<int>q; q.push(0); used[0]=true; while(!q.empty()){ int x=q.front(); q.pop(); for(int y:g[x]){ if(!used[y]){ used[y]=true; if(stype[x]==1){ location[y]=location[x]+dist[x][y]; stype[y]=2; } else{ location[y]=location[x]-dist[x][y]; stype[y]=1; } q.push(y); } } } for(auto [x,y]:v){ if(used[x]||used[y]) continue; if(dist[x][0]==dist[x][D]+dist[D][0]){//Left if(dist[x][D]>dist[y][D]){ swap(x,y);//x then y } location[x]=location[D]-dist[D][x]; location[y]=location[x]+dist[x][y]; stype[x]=1; stype[y]=2; } else{//Right if(dist[x][0]>dist[y][0]){ swap(x,y);//y then x } location[x]=location[D]+dist[D][x]; location[y]=location[x]-dist[x][y]; stype[x]=2; stype[y]=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...