제출 #84267

#제출 시각아이디문제언어결과실행 시간메모리
84267shoemakerjo여행하는 상인 (APIO17_merchant)C++14
100 / 100
118 ms10568 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> #define maxn 101 #define maxk 1010 int N, M, K; const ll inf = 1e18; ll dist[maxn][maxn]; ll buy[maxn][maxk]; ll sell[maxn][maxk]; ll profit[maxn][maxn]; ll d2[maxn][maxn]; bool check(ll val) { for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { d2[i][j] = profit[i][j] - val*min(inf/val, dist[i][j]); } } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { for (int k = 1; k <= N; k++) { d2[j][k] = max(d2[j][k], d2[j][i] + d2[i][k]); } } } for (int i = 1; i <= N; i++) { if (d2[i][i] >= 0) return true; } return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> N >> M >> K; for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { dist[i][j] = inf; } dist[i][i] = inf; } for (int i = 1; i <= N; i++) { for (int j = 1; j <= K; j++) { cin >> buy[i][j] >> sell[i][j]; } } int vp, wp; ll tp; for (int i = 0; i < M; i++) { cin >> vp >> wp >> tp; dist[vp][wp] = min(dist[vp][wp], tp); } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { for (int k = 1; k <= N; k++) { dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]); } } } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { if (i == j) continue; for (int k = 1; k <= K; k++) { if (buy[i][k] == -1 || sell[j][k] == -1) continue; profit[i][j] = max(profit[i][j], sell[j][k] - buy[i][k]); } } } ll lo = 0LL; ll hi = 1e12; while (lo < hi) { ll mid = (lo+hi+1)/2LL; if (check(mid)) { lo = mid; } else hi = mid-1; } cout << lo << 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...