Submission #161839

#TimeUsernameProblemLanguageResultExecution timeMemory
161839MinnakhmetovTravelling Merchant (APIO17_merchant)C++14
21 / 100
144 ms2676 KiB
#include <bits/stdc++.h> #define ll long long #define all(aaa) aaa.begin(), aaa.end() using namespace std; const int N = 105, C = 1000, INF = 2e9; ll prof[N][N], dp[N][N], b[N][N], s[N][N], w[N][N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int n, m, k; cin >> n >> m >> k; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { w[i][j] = INF; } } 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 < m; i++) { ll a, b, c; cin >> a >> b >> c; a--, b--; w[a][b] = min(w[a][b], c); } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { if (w[j][i] != INF && w[i][k] != INF) { w[j][k] = min(w[j][k], w[j][i] + w[i][k]); } } } } // for (int i = 0; i < n; i++) { // for (int j = 0; j < n; j++) { // cout << w[i][j] << " "; // } // cout << "\n"; // } for (int x = 0; x < n; x++) { for (int y = 0; y < n; y++) { for (int z = 0; z < k; z++) { if (b[x][z] != -1 && s[y][z] != -1) { prof[x][y] = max(prof[x][y], s[y][z] - b[x][z]); } } } } ll l = 0, r = 3e9; while (r - l > 1) { ll p = (l + r) >> 1; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (w[i][j] != INF) { dp[i][j] = prof[i][j] - w[i][j] * p; } } } bool ok = false; for (int x = 0; x < n; x++) { for (int y = 0; y < n; y++) { for (int z = 0; z < n; z++) { if (w[y][x] != INF && w[x][z] != INF) { dp[y][z] = max(dp[y][z], dp[y][x] + dp[x][z]); if (y == z && dp[y][z] >= 0) { ok = true; } } } } } if (ok) { l = p; } else { r = p; } } cout << l; 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...