Submission #487643

#TimeUsernameProblemLanguageResultExecution timeMemory
487643leakedTravelling Merchant (APIO17_merchant)C++14
100 / 100
182 ms4480 KiB
#include <bits/stdc++.h> #define f first #define s second #define vec vector #define pb push_back #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define pw(x) (1LL<<(x)) #define sz(x) (int)(x).size() #define fast_iati ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);} template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);} typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll>pll; const int N=201; const int K=2001; const ll inf=1e16; int b[N][K],s[N][K]; ll dst[N][N]; ll mx[N][N]; signed main(){ fast_iati; int n,m,k; cin>>n>>m>>k; for(int i=0;i<n;i++){ for(int j=0;j<k;j++){ cin>>b[i][j]>>s[i][j]; } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(i==j) continue; for(int t=0;t<k;t++){ if(b[i][t]==-1 || s[j][t]==-1) continue; umax(mx[i][j],(ll)-b[i][t]+s[j][t]); } } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++) dst[i][j]=inf; dst[i][i]=0; } for(int i=0;i<m;i++){ int v,u,w; cin>>v>>u>>w;--v;--u; umin(dst[v][u],(ll)w); } for(int t=0;t<n;t++){ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ umin(dst[i][j],dst[i][t]+dst[t][j]); } } } auto check=[&](ll x){ vec<vec<ll>>f(n,vec<ll>(n,-inf)); for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(dst[i][j]<=inf/x && i!=j){ umax(f[i][j],mx[i][j]-1ll*x*dst[i][j]); } } } for(int k=0;k<n;k++){ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ umax(f[i][j],min(inf,f[i][k]+f[k][j])); } } } for(int i=0;i<n;i++){ if(f[i][i]>=0) return 1; } // int ok=(f[0][0]>=0); return 0; }; // cout<<check(3); // return 0; ll l=1,r=inf; while(l!=r){ ll mid=(l+r)/2; if(check(mid)) l=mid+1; else r=mid; } cout<<l-1; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...