제출 #699387

#제출 시각아이디문제언어결과실행 시간메모리
699387CatalinT여행하는 상인 (APIO17_merchant)C++17
33 / 100
57 ms1236 KiB
#include <vector> #include <iostream> #include <cassert> #include <algorithm> #include <numeric> #include <iostream> #include <set> #include <map> #include <string> #include <unordered_map> #include <functional> #include <bitset> #include <sstream> using namespace std; using int64 = long long; const double EPS = 1e-9; const int INF = (1<<30); struct Market { int b; int s; }; int N, M, K; vector<vector<Market>> market; vector<vector<int>> dist; vector<vector<pair<int, int>>> edges; bool go(int64 r) { vector<vector<int64>> d(N, vector<int64>(N, (1LL<<60))); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (i != j && dist[i][j] != INF) { d[i][j] = -edges[i][j].first + r * dist[i][j]; } else { d[i][j] = (1LL<<60); } } } for (int k = 0; k < N; k++) for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]); for (int i = 0; i < N; i++) { if (d[i][i] <= 0) return true; } return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> N >> M >> K; market = vector<vector<Market>>(N, vector<Market>(K)); for (int i = 0; i < N; i++) { for (int j = 0; j < K; j++) { cin >> market[i][j].b >> market[i][j].s; } } dist = vector<vector<int>>(N, vector<int>(N, INF)); for (int i = 0; i < M; i++) { int x, y, w; cin >> x >> y >> w; x--, y--; dist[x][y] = min(dist[x][y], w); } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { for (int k = 0; k < N; k++) { if (i != k && k != j && j != i && dist[i][k] < INF && dist[k][j] < INF) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } } } edges = vector<vector<pair<int, int>>>(N, vector<pair<int, int>>(N, {0, 0})); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (dist[i][j] < INF) { // i -> j int up = 0; for (int k = 0; k < K; k++) { if (market[i][k].b != -1 && market[j][k].s != -1) { up = max(up, market[j][k].s - market[i][k].b); } } edges[i][j] = {up, dist[i][j]}; } } } int64 l = 0, r = (1LL<<30), sol = -1; while (l <= r) { int64 m = (l + r) >> 1; if (go(m)) { sol = m; l = m + 1; } else { r = m - 1; } } cout << sol << "\n"; 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...