# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
407046 | Waratpp123 | Travelling Merchant (APIO17_merchant) | C++14 | 148 ms | 4088 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
long long buy[105][1005],sell[105][1005],dis[105][105],prof[105][105],eff[105][105];
int main(){
long long i,j,n,m,k,p,u,v,w,l,r,mid;
scanf("%lld %lld %lld",&n,&m,&p);
for(i=1;i<=n;i++){
for(j=1;j<=p;j++){
scanf("%lld %lld",&buy[i][j],&sell[i][j]);
}
}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
dis[i][j]=2e9;
prof[i][j]=0;
}
}
for(i=1;i<=m;i++){
scanf("%lld %lld %lld",&u,&v,&w);
dis[u][v]=w;
}
for(k=1;k<=n;k++){
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
if(dis[i][k]+dis[k][j]<dis[i][j]){
dis[i][j]=dis[i][k]+dis[k][j];
}
}
}
}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
if(dis[i][j]>=2e9){
prof[i][j]=-2e9;
continue;
}
int ch=0;
for(k=1;k<=p;k++){
if(sell[j][k]!=-1&&buy[i][k]!=-1) ch=1,prof[i][j]=max(prof[i][j],sell[j][k]-buy[i][k]);
}
}
}
l=0,r=2e9;
while(l<r){
mid=(l+r+1)/2;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
if(dis[i][j]<2e9) eff[i][j]=prof[i][j]-mid*dis[i][j];
else eff[i][j]=-2e9;
}
}
for(k=1;k<=n;k++){
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
if(dis[i][k]<2e9 && dis[k][j]<2e9) eff[i][j]=max(eff[i][j],eff[i][k]+eff[k][j]);
}
}
}
int ch=0;
for(i=1;i<=n;i++) if(eff[i][i]>=0) ch=1;
if(ch==1) l=mid;
else r=mid-1;
}
printf("%lld\n",l);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |