Submission #264015

#TimeUsernameProblemLanguageResultExecution timeMemory
264015defineTravelling Merchant (APIO17_merchant)C++17
100 / 100
573 ms2168 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define rep(i,n) for(int i=0;i<n;i++) #define REP(i,n) for(int i=1;i<n;i++) #define rev(i,n) for(int i=n-1;i>=0;i--) #define all(v) v.begin(),v.end() #define P pair<int,int> #define len(s) (int)s.size() template<class T> inline bool chmin(T &a, T b){ if(a>b){a=b;return true;} return false; } template<class T> inline bool chmax(T &a, T b){ if(a<b){a=b;return true;} return false; } constexpr int mod = 1e9+7; constexpr long long inf = 3e18; int N,M,K; int sell[105][1005],buy[105][1005]; int dis[105][105]; int ben[105][105]; bool isOk(int x){ rep(i,N){ rep(j,N){ if(i!=j){ int mx=0; rep(k,K){ if(sell[j][k]==-1||buy[i][k]==-1)continue; chmax(mx,sell[j][k]-buy[i][k]); } if(inf/x<dis[i][j])ben[i][j]=-inf; else ben[i][j]=mx-x*dis[i][j]; }else ben[i][j]=-inf; } } rep(k,N)rep(i,N)rep(j,N)chmax(ben[i][j],ben[i][k]+ben[k][j]); bool flag=false; rep(i,N)flag|=ben[i][i]>=0; return flag; } signed main(){ cin.tie(0);ios::sync_with_stdio(false); cin>>N>>M>>K; rep(i,N)rep(j,K)cin>>buy[i][j]>>sell[i][j]; rep(i,N)rep(j,N)if(i!=j)dis[i][j]=inf; rep(i,M){ int a,b,c;cin>>a>>b>>c;a--;b--; chmin(dis[a][b],c); } rep(k,N)rep(i,N)rep(j,N)chmin(dis[i][j],dis[i][k]+dis[k][j]); int ok=0,ng=1e11; while(ng-ok>1){ int mid=(ok+ng)/2; if(isOk(mid))ok=mid; else ng=mid; } cout<<ok<<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...