Submission #987574

#TimeUsernameProblemLanguageResultExecution timeMemory
987574aykhnTravelling Merchant (APIO17_merchant)C++17
100 / 100
73 ms5212 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define inf 0x3F3F3F3F const int MXN = 2e2 + 5; const int MXM = 1e3 + 5; int n, m, k; int d[MXN][MXN], nd[MXN][MXN], w[MXN][MXN]; int B[MXN][MXM], S[MXN][MXM]; // 0 >= x * t - p int ok(int val) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { nd[i][j] = d[i][j] * val - w[i][j]; } } for (int k = 1; k <= n; k++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { nd[i][j] = min(nd[i][j], nd[i][k] + nd[k][j]); } } } for (int i = 1; i <= n; i++) { if (nd[i][i] <= 0) return 1; } return 0; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> k; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { d[i][j] = inf; } } 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 <= m; i++) { int u, v, t; cin >> u >> v >> t; d[u][v] = min(d[u][v], t); } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { for (int l = 1; l <= k; l++) { if (B[i][l] != -1 && S[j][l] != -1) w[i][j] = max(w[i][j], S[j][l] - B[i][l]); } } } for (int k = 1; k <= n; k++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } int l = 0, r = inf; while (l < r) { int mid = (l + r + 1) >> 1; if (ok(mid)) l = mid; else r = mid - 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...