제출 #53943

#제출 시각아이디문제언어결과실행 시간메모리
53943MatheusLealV여행하는 상인 (APIO17_merchant)C++17
100 / 100
102 ms2552 KiB
#include <bits/stdc++.h> #define N 105 #define M 1005 #define inf 1000000000000000000 using namespace std; typedef long long ll; int n, m, k; ll opt[N][N], B[N][M], S[N][M], dist[N][N], dp[N][N]; inline bool check(ll x) { for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) if(dist[i][j] == inf) dp[i][j] = inf; else dp[i][j] = x*dist[i][j] - opt[i][j]; } for(int k = 1; k <= n; k++) for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]); for(int i = 1; i <= n; i++) if(dp[i][i] <= 0) return true; return false; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>m>>k; for(int i = 1; i <= n; i++) for(int j = 1; j <= k; j++) cin>>B[i][j]>>S[i][j]; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) dist[i][j] = inf; for(int i = 1, a, b, c; i <= m; i++) { cin>>a>>b>>c; dist[a][b] = c; } for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) for(int q = 1; q <= k; q++) if(B[i][q] >= 0 and S[j][q] >= 0) opt[i][j] = max(opt[i][j], -B[i][q] + S[j][q]); for(int k = 1; k <= n; k++) for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); ll ini = 0, fim = 1e9 + 500, mid, best = 0; while(fim >= ini) { mid = (ini + fim)/2; if(check(mid)) best = mid, ini = mid + 1; else fim = mid - 1; } cout<<best<<"\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...