Submission #111529

#TimeUsernameProblemLanguageResultExecution timeMemory
111529SegtreeTravelling Merchant (APIO17_merchant)C++14
100 / 100
528 ms3960 KiB
#include<iostream> #include<algorithm> using namespace std; typedef long double ll; typedef long double ld; #define chmax(a,b) a=max(a,b); #define chmin(a,b) a=min(a,b); #define N 110 #define K 1010 ll n,m,k,d[N][N],v[N][N]; ll s[N][K],b[N][K]; void wf(){ for(int r=1;r<=n;r++){ for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){ d[i][j]=min(d[i][j],d[i][r]+d[r][j]); } } } ld dist[N]; bool solve(ll t){ /*cout<<"-----"<<t<<endl; for(int i=1;i<=n;i++){ cout<<i<<":"; for(int j=1;j<=n;j++)cout<<v[i][j]-t*d[i][j]<<" "; cout<<endl; }*/ for(int i=1;i<=n;i++)dist[i]=0; for(int u=0;u<=N;u++){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++)if(i!=j){ ld ne=dist[i]-(v[i][j]-t*d[i][j]+1e-5); if(u==N&&dist[j]>ne)return 1; chmin(dist[j],ne); } } } return 0; } int main(){ cin>>n>>m>>k; for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){ d[i][j]=1e17; } for(int i=1;i<=n;i++){ for(int j=0;j<k;j++){ cin>>b[i][j]>>s[i][j]; d[i][i]=0; } } for(int i=0;i<m;i++){ ll x,y,z;cin>>x>>y>>z; d[(int)x][(int)y]=z; } wf(); /* for(int i=1;i<=n;i++){ cout<<i<<":"; for(int j=1;j<=n;j++)cout<<d[i][j]<<" "; cout<<endl; }*/ for(int r=1;r<=n;r++){ for(int i=1;i<=n;i++){ ll ma=0; for(int j=0;j<k;j++){ if(-1!=s[i][j]&&-1!=b[r][j])ma=max(ma,s[i][j]-b[r][j]); } v[r][i]=ma; } } long long l=0,r=2e9,mid; while(l<r-1){ mid=(l+r)/2; if(solve(mid))l=mid; else r=mid; } cout<<l<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...