Submission #548207

#TimeUsernameProblemLanguageResultExecution timeMemory
548207Soumya1Travelling Merchant (APIO17_merchant)C++17
100 / 100
100 ms3484 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) { __int128 d[mxN]; __int128 edge[mxN][mxN]; for (int i = 1; i <= n; i++) { d[i] = INF; for (int j = 1; j <= n; j++) { edge[i][j] = (__int128) x * dist[i][j] - profit[i][j]; } } for (int l = 1; l <= n; l++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { edge[i][j] = min(edge[i][j], edge[i][l] + edge[l][j]); } } } for (int i = 1; i <= n; i++) { if (edge[i][i] <= 0) 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; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { cin >> b[i][j] >> 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; }

Compilation message (stderr)

merchant.cpp: In function 'bool f(int)':
merchant.cpp:36:12: warning: variable 'd' set but not used [-Wunused-but-set-variable]
   36 |   __int128 d[mxN];
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...