Submission #58786

#TimeUsernameProblemLanguageResultExecution timeMemory
58786HoppaTravelling Merchant (APIO17_merchant)C++14
100 / 100
293 ms14584 KiB
#include <bits/stdc++.h> using namespace std; int n,m,k,u,v; long long w,buy[105][1005],sell[105][1005],d[105][105],profit[105][105],f[105][105],ans; int check(long long val) { for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) f[i][j]=profit[i][j]-val*d[i][j]; for(int kk=1;kk<=n;kk++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i!=j && d[i][kk]<1e9 && d[kk][j]<1e9) f[i][j]=max(f[i][j],f[i][kk]+f[kk][j]); for(int i=1;i<n;i++) for(int j=i+1;j<=n;j++) if(f[i][j]+f[j][i]>=0 && d[i][j]<1e9 && d[j][i]<1e9) return 1; return 0; } int main() { cin>>n>>m>>k; for(int i=1;i<=n;i++) for(int j=1;j<=k;j++) cin>>buy[i][j]>>sell[i][j]; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) d[i][j]=1e9; d[i][i]=0; } for(int i=1;i<=m;i++) { cin>>u>>v>>w; d[u][v]=w; } for(int kk=1;kk<=n;kk++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) d[i][j]=min(d[i][j],d[i][kk]+d[kk][j]); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) for(int kk=1;kk<=k;kk++) if(buy[i][kk]!=-1 && sell[j][kk]!=-1) profit[i][j]=max(profit[i][j],sell[j][kk]-buy[i][kk]); long long l=1,r=1e9; while(l<=r) { long long mid=(l+r)/2; if(check(mid)==1) { ans=mid; l=mid+1; } else r=mid-1; } cout<<ans<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...