제출 #408991

#제출 시각아이디문제언어결과실행 시간메모리
408991amunduzbaev여행하는 상인 (APIO17_merchant)C++14
100 / 100
197 ms4268 KiB
#include "bits/stdc++.h" using namespace std; #define int long long template<class T> bool umin(T& a, const T b) { if(a > b) { a = b; return 1; } return 0; } template<class T> bool umax(T& a, const T b) { if(a < b) { a = b; return 1; } return 0; } const int N = 105; const int mod = 1e9+7; const long long inf = 1e18+7; int n, m, k, a[N][N]; int gg[N][N], b[N][1005], s[N][1005], prof[N][N]; bool check(int m){ for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) a[i][j] = -inf; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(gg[i][j] == inf) continue; umax(a[i][j], prof[i][j] - gg[i][j] * m); } } for(int k=1;k<=n;k++){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ umax(a[i][j], a[i][k] + a[k][j]); } } } for(int i=1;i<=n;i++) if(a[i][i] >= 0) return 1; return 0; } /* 4 5 2 10 9 5 2 6 4 20 15 9 7 10 9 -1 -1 16 11 1 2 3 2 3 3 1 4 1 4 3 1 3 1 1 */ signed main(){ cin>>n>>m>>k; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) gg[i][j] = inf; for(int i=1;i<=n;i++){ for(int j=0;j<k;j++){ cin>>b[i][j]>>s[i][j]; } } for(int i=0;i<m;i++){ int a, b, c; cin>>a>>b>>c; umin(gg[a][b], c); } for(int k=1;k<=n;k++){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ umin(gg[i][j], gg[i][k] + gg[k][j]); } } } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ for(int l=0;l<k;l++){ if(~b[i][l] && ~s[j][l]) umax(prof[i][j], - b[i][l] + s[j][l]); } } } int l = 0, r = mod; while(l < r){ int m = (l + r + 1)>>1; if(check(m)) l = m; else r = m - 1; } cout<<l<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...