Submission #1091197

#TimeUsernameProblemLanguageResultExecution timeMemory
1091197anmattroiTravelling Merchant (APIO17_merchant)C++14
100 / 100
112 ms3412 KiB
#include <bits/stdc++.h> #define maxn 101 #define maxm 9901 #define maxk 1001 #define fi first #define se second using namespace std; typedef pair<int, int> ii; int n, m, k; int s[maxn][maxk], b[maxn][maxk]; int c[maxn][maxn]; int64_t kc[maxn][maxn]; int64_t dp[maxn][maxn]; struct edge { int u, v, l; edge() {} edge(int _u, int _v, int _l) : u(_u), v(_v), l(_l) {} }; edge e[maxm]; bool ok(int x) { for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) kc[i][j] = LLONG_MAX/2; for (int i = 1; i <= n; i++) kc[i][i] = 0; for (int i = 1; i <= m; i++) { int u = e[i].u, v = e[i].v, l = e[i].l; kc[u][v] = min(kc[u][v], int64_t(l)*x); } for (int i = 1; i <= n; i++) kc[i][i] = LLONG_MAX/2; for (int k = 1; k <= n; k++) { for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) kc[i][j] = min(kc[i][j], kc[i][k] + kc[k][j]); } for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { if (kc[i][j] == LLONG_MAX/2) dp[i][j] = LLONG_MAX/2; else dp[i][j] = kc[i][j] - c[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(NULL); 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 <= m; i++) { int u, v, l; cin >> u >> v >> l; e[i] = edge(u, v, l); } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (i == j) continue; for (int o = 1; o <= k; o++) { if (b[i][o] == -1 || s[j][o] == -1) continue; c[i][j] = max(c[i][j], s[j][o] - b[i][o]); } } } int lo = 0, hi = 1000000001; while (hi - lo > 1) { int mid = (lo + hi)>>1; if (ok(mid)) lo = mid; else hi = mid; } // ok(2); // ok(3); // ok(6); cout << lo; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...