제출 #699389

#제출 시각아이디문제언어결과실행 시간메모리
699389CatalinT여행하는 상인 (APIO17_merchant)C++17
0 / 100
54 ms1252 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<int>> profit; 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] = -profit[i][j] + 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++) dist[i][i] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { for (int k = 0; k < N; k++) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } } profit = vector<vector<int>>(N, vector<int>(N)); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (dist[i][j] < INF) { for (int k = 0; k < K; k++) { if (market[i][k].b != -1 && market[j][k].s != -1) { profit[i][j] = max(profit[i][j], market[j][k].s - market[i][k].b); } } } } } int64 l = 0, r = (1LL<<30), sol = 0; 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...