제출 #733415

#제출 시각아이디문제언어결과실행 시간메모리
7334151075508020060209tc여행하는 상인 (APIO17_merchant)C++14
100 / 100
247 ms6532 KiB
#include<bits/stdc++.h> using namespace std; #define int __int128 int n;int m;int K; int buy[110][1100]; int sell[110][1100]; int odis[110][110]; int dis[110][110]; int tmp[110][110]; int mer[110][110]; int ok(int mi){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ dis[i][j]=odis[i][j]*mi*-1+mer[i][j]; } } for(int md=1;md<=n;md++){ for(int a=1;a<=n;a++){ for(int b=1;b<=n;b++){ dis[a][b]=max(dis[a][b],dis[a][md]+dis[md][b]); tmp[a][b]=dis[a][b]; } } } for(int md=1;md<=n;md++){ for(int a=1;a<=n;a++){ for(int b=1;b<=n;b++){ dis[a][b]=max(dis[a][b],dis[a][md]+dis[md][b]); } } } for(int a=1;a<=n;a++){ for(int b=1;b<=n;b++){ if(tmp[a][b]!=dis[a][b]){return 1;} } } for(int a=1;a<=n;a++){ for(int b=1;b<=n;b++){ if(a==b){continue;} if(dis[a][b]+dis[b][a]>=0){return 1;} } } return 0; } int read(){ long long ret; cin>>ret; return ret; } signed main(){ cin.tie(0); ios_base::sync_with_stdio(0); n=read();m=read();K=read(); for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ odis[i][j]=1e18; } } for(int i=1;i<=n;i++){ odis[i][i]=0; } for(int i=1;i<=n;i++){ for(int j=1;j<=K;j++){ buy[i][j]=read();sell[i][j]=read(); // cin>>buy[i][j]>>sell[i][j]; } } for(int i=1;i<=m;i++){ int a;int b;int c; //cin>>a>>b>>c; a=read();b=read();c=read(); odis[a][b]=min(odis[a][b],c); } for(int md=1;md<=n;md++){ for(int a=1;a<=n;a++){ for(int b=1;b<=n;b++){ odis[a][b]=min(odis[a][b],odis[a][md]+odis[md][b]); } } } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ for(int k=1;k<=K;k++){ if(buy[i][k]==-1||sell[j][k]==-1){continue;} mer[i][j]=max(mer[i][j],sell[j][k]-buy[i][k]); } } } int l=0;int r=1e9; while(l<r){ int mi=l+(r-l+1)/2; if(ok(mi)){ l=mi; }else{ r=mi-1; } } long long op=l; cout<<op<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...