제출 #263891

#제출 시각아이디문제언어결과실행 시간메모리
263891define여행하는 상인 (APIO17_merchant)C++11
0 / 100
724 ms2808 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]; double ben[105][105]; bool isOk(int x){ rep(i,N){ rep(j,N){ if(i!=j){ int mx=-inf; rep(k,K){ if(sell[j][k]==-1||buy[i][k]==-1)continue; chmax(mx,sell[j][k]-buy[i][k]); } ben[i][j]=(double)mx/dis[i][j]-x; }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=inf; 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...