제출 #531464

#제출 시각아이디문제언어결과실행 시간메모리
531464Alex_tz307여행하는 상인 (APIO17_merchant)C++17
33 / 100
76 ms2116 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int INF = 2e18L; void maxSelf(int &x, int y) { if (x < y) { x = y; } } void minSelf(int &x, int y) { if (y < x) { x = y; } } void FloydWarshall(vector<vector<int>> &d) { int n = d.size() - 1; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { for (int k = 1; k <= n; ++k) { minSelf(d[i][j], d[i][k] + d[k][j]); } } } } void testCase() { int n, m, k; cin >> n >> m >> k; vector<vector<int>> b(n + 1, vector<int>(k + 1)), s(n + 1, vector<int>(k + 1)); vector<vector<int>> d(n + 1, vector<int>(n + 1, INF)); for (int u = 1; u <= n; ++u) { for (int i = 1; i <= k; ++i) { cin >> b[u][i] >> s[u][i]; } } for (int i = 0; i < m; ++i) { int u, v, w; cin >> u >> v >> w; d[u][v] = w; } FloydWarshall(d); vector<vector<int>> profit(n + 1, vector<int>(n + 1)); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { for (int p = 1; p <= k; ++p) { if (b[i][p] != -1 && s[j][p] != -1) { maxSelf(profit[i][j], s[j][p] - b[i][p]); } } } } int l = 1, r = 1e9; while (l <= r) { int mid = (l + r) / 2; vector<vector<int>> dp(n + 1, vector<int>(n + 1)); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { dp[i][j] = (int)mid * min(d[i][j], INF / mid) - profit[i][j]; } } FloydWarshall(dp); bool ok = false; for (int v = 1; v <= n; ++v) { if (dp[v][v] <= 0) { ok = true; } } if (ok) { l = mid + 1; } else { r = mid - 1; } } cout << r << '\n'; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int tests = 1; for (int tc = 0; tc < tests; ++tc) { testCase(); } 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...