Submission #548196

#TimeUsernameProblemLanguageResultExecution timeMemory
548196Soumya1Travelling Merchant (APIO17_merchant)C++17
0 / 100
72 ms2600 KiB
#include <bits/stdc++.h> #ifdef __LOCAL__ #include <debug_local.h> #endif using namespace std; const int mxN = 101; const int mxK = 1001; const long long INF = 1e18; int s[mxN][mxK], b[mxN][mxK]; long long dist[mxN][mxN]; long long profit[mxN][mxN]; int n, m, k; void pre_calc() { for (int x = 1; x <= n; x++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { dist[i][j] = min(dist[i][j], dist[i][x] + dist[x][j]); } } } for (int item = 1; item <= k; item++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (i == j) { profit[i][j] = 0; continue; } if (b[i][item] != -1 && s[j][item] != -1) { profit[i][j] = max(profit[i][j], (long long) s[j][item] - b[i][item]); } } } } } bool f(int x) { long long d[mxN]; long long edge[mxN][mxN]; for (int i = 1; i <= n; i++) { d[i] = INF; for (int j = 1; j <= n; j++) { edge[i][j] = 1LL * x * dist[i][j] - profit[i][j]; } } for (int i = 1; i <= n; i++) d[i] = INF; d[1] = 0; for (int it = 0; it < n - 1; it++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (d[i] != INF && d[j] > d[i] + edge[i][j]) { d[j] = d[i] + edge[i][j]; } } } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (d[i] != INF && d[j] > d[i] + edge[i][j]) { return true; } } } return false; } void testCase() { cin >> n >> m >> k; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { dist[i][j] = INF; profit[i][j] = 0; } dist[i][i] = 0; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { cin >> b[i][j]; } for (int j = 1; j <= k; j++) { cin >> s[i][j]; } } while (m--) { int u, v, w; cin >> u >> v >> w; dist[u][v] = min(dist[u][v], 1LL * w); } pre_calc(); int lo = 0, hi = 1e9 + 5; while (lo < hi) { int mid = (lo + hi + 1) >> 1; if (f(mid)) lo = mid; else hi = mid - 1; } cout << lo << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); 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...