제출 #842631

#제출 시각아이디문제언어결과실행 시간메모리
842631tch1cherin여행하는 상인 (APIO17_merchant)C++17
100 / 100
88 ms2652 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, w; cin >> u >> v >> w; u--, v--; G[u].push_back({v, w}); } vector<vector<int>> profit(N, vector<int>(N)); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) if (i != j) for (int k = 0; k < K; k++) if (S[j][k] != -1 && B[i][k] != -1) profit[i][j] = max(profit[i][j], S[j][k] - B[i][k]); vector<vector<long long>> dist(N, vector<long long>(N, INF)); for (int u = 0; u < N; u++) { dist[u][u] = 0; 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]); int l = 0, r = 1 << 30; while (r > l + 1) { int mid = (l + r) / 2; vector<vector<long long>> cost(N, vector<long long>(N)); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (dist[i][j] == INF || i == j) { cost[i][j] = INF; } else { cost[i][j] = 1LL * 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++) { cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]); cost[i][j] = max(cost[i][j], -INF); cost[i][j] = min(cost[i][j], INF); } bool good = false; for (int i = 0; i < N; i++) { if (cost[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...