Submission #840108

#TimeUsernameProblemLanguageResultExecution timeMemory
840108tch1cherinTravelling Merchant (APIO17_merchant)C++17
33 / 100
68 ms1344 KiB
#include <bits/stdc++.h> using namespace std; const long long INF = 1ll << 60; int main() { cin.tie(nullptr)->sync_with_stdio(false); int N, M, K; cin >> N >> M >> K; vector<vector<int>> B(N, vector<int>(K)), S(N, vector<int>(K)); for (int i = 0; i < N; i++) { for (int j = 0; j < K; j++) { cin >> B[i][j] >> S[i][j]; } } vector<vector<pair<int, int>>> G(N); for (int i = 0; i < M; i++) { int u, v, t; cin >> u >> v >> t; u--, v--; G[u].push_back({v, t}); } vector dist(N, vector<long long>(N, INF)); for (int u = 0; u < N; u++) { for (auto [v, t] : G[u]) { dist[u][v] = t; } } for (int k = 0; k < N; k++) for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); vector profit(N, vector<long long>(N)); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) for (int k = 0; k < K; k++) if (B[i][k] != -1 && S[j][k] != -1) profit[i][j] = max(profit[i][j], (long long)S[j][k] - B[i][k]); int l = -1, r = 1 << 30; while (r > l + 1) { int mid = (l + r) / 2; vector dis(N, vector<long long>(N, INF)); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) dis[i][j] = min(INF, 1LL * min(2 * INF / mid, dist[i][j]) * mid - profit[i][j]); for (int k = 0; k < N; k++) for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]); bool good = false; for (int i = 0; i < N; i++) { if (dis[i][i] <= 0) { good = true; } } if (good) { l = mid; } else { r = mid; } } cout << l << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...