Submission #1117188

#TimeUsernameProblemLanguageResultExecution timeMemory
1117188ThegeekKnight16Travelling Merchant (APIO17_merchant)C++17
0 / 100
48 ms2128 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int INF = 0x3f3f3f3f3f3f3f3f; bool bellman(int x, const vector<vector<int>> &dist, const vector<vector<int>> &maxDiff, int N) { vector<int> d(N+1, INF); vector<vector<int>> peso(N+1, vector<int>(N+1)); for (int i = 1; i <= N; i++) for (int j = 1; j <= N; j++) peso[i][j] = x*dist[i][j] - maxDiff[i][j]; for (int t = 1; t <= N; t++) for (int i = 1; i <= N; i++) for (int j = 1; j <= N; j++) d[j] = min(d[j], d[i] + peso[i][j]); for (int i = 1; i <= N; i++) for (int j = 1; j <= N; j++) if (d[j] > d[i] + peso[i][j]) return true; return false; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N, M, K; cin >> N >> M >> K; vector<vector<pair<int, int>>> items(N+1, vector<pair<int, int>>(K)); for (int i = 1; i <= N; i++) for (auto &[B,S] : items[i]) {cin >> B >> S;} vector<vector<int>> maxDiff(N+1, vector<int>(N+1)); for (int i = 1; i <= N; i++) for (int j = 1; j <= N; j++) { if (i == j) continue; for (int k = 0; k < K; k++) { auto [Bi, Si] = items[i][k]; auto [Bj, Sj] = items[j][k]; if (Bi == -1 || Sj == -1) continue; if (Bi > Sj) continue; maxDiff[i][j] = max(maxDiff[i][j], Sj - Bi); } } items.clear(); vector<vector<int>> dist(N+1, vector<int>(N+1, INF)); for (int i = 1; i <= M; i++) { int X, Y, P; cin >> X >> Y >> P; dist[X][Y] = min(dist[X][Y], P); } for (int i = 1; i <= N; i++) dist[i][i] = 0; 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]); int ini = -1, fim = (int)1e9 + 10; while (ini < fim) { int m = (ini + fim + 1) >> 1; if (bellman(m, dist, maxDiff, N)) ini = m; else fim = m-1; } cout << ini+1 << '\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...