Submission #410753

#TimeUsernameProblemLanguageResultExecution timeMemory
410753600MihneaTravelling Merchant (APIO17_merchant)C++17
100 / 100
124 ms2172 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 100 + 7; const int K = 1000 + 7; const int INF = (int) 1e18; int dist[N][N]; int n, m, k, buy[N][K], sell[N][K], best[N], tab[N][N], sol[N][N]; bool ok(int coef) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { sol[i][j] = -INF; if (dist[i][j] == INF) continue; int mx = tab[i][j]; sol[i][j] = mx - coef * dist[i][j]; } } for (int k = 1; k <= n; k++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { sol[i][j] = max(sol[i][j], sol[i][k] + sol[k][j]); sol[i][j] = min(sol[i][j], INF); } } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (sol[i][j] + sol[j][i] >= 0) { return 1; } } } return 0; } signed main() { ios::sync_with_stdio(0); cin.tie(0); ///freopen ("input", "r", stdin); cin >> n >> m >> k; for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { cin >> buy[i][j] >> sell[i][j]; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { dist[i][j] = INF; } } for (int i = 1; i <= m; i++) { int a, b, c; cin >> a >> b >> c; dist[a][b] = c; } for (int k = 1; k <= n; k++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { for (int item = 1; item <= k; item++) { /// buy at i, sell at j if (buy[i][item] != -1 && sell[j][item] != -1) { tab[i][j] = max(tab[i][j], sell[j][item] - buy[i][item]); } } } } int l = 1, r = (int) 1e9, sol = 0; while (l <= r) { int m = (l + r) / 2; if (ok(m)) { sol = m; l = m + 1; } else { r = m - 1; } } assert(!ok(sol + 1)); cout << sol << "\n"; 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...