제출 #409111

#제출 시각아이디문제언어결과실행 시간메모리
409111cheissmart여행하는 상인 (APIO17_merchant)C++14
100 / 100
103 ms3332 KiB
#include <bits/stdc++.h> #define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0); #define F first #define S second #define V vector #define PB push_back #define MP make_pair #define EB emplace_back #define ALL(v) (v).begin(), (v).end() using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef V<int> vi; string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m"; void DBG() { cerr << "]" << _reset << endl; } template<class H, class...T> void DBG(H h, T ...t) { cerr << to_string(h); if(sizeof ...(t)) cerr << ", "; DBG(t...); } #ifdef CHEISSMART #define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__) #else #define debug(...) #endif const int INF = 0x3f3f3f3f, N = 105, K = 1005; const ll oo = 1e18; const double eps = 1e-9; int cost[N][K][2]; int a[N][N], b[N][N]; ll c[N][N]; signed main() { IO_OP; memset(a, 0x3f, sizeof a); int n, m, k; cin >> n >> m >> k; for(int i = 0; i < n; i++) for(int j = 0; j < k; j++) { cin >> cost[i][j][0] >> cost[i][j][1]; } for(int i = 0; i < n; i++) a[i][i] = 0; for(int i = 0; i < m; i++) { int u, v, w; cin >> u >> v >> w; u--, v--; a[u][v] = min(a[u][v], w); } for(int k = 0; k < n; k++) for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) a[i][j] = min(a[i][j], a[i][k] + a[k][j]); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) for(int l = 0; l < k; l++) { if(cost[j][l][1] != -1 && cost[i][l][0] != -1) b[i][j] = max(b[i][j], cost[j][l][1] - cost[i][l][0]); } auto ok = [&] (ll eff) { for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) { if(i == j) c[i][j] = INF; else if(a[i][j] < INF) c[i][j] = a[i][j] * eff - b[i][j]; else c[i][j] = oo; } for(int k = 0; k < n; k++) for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) c[i][j] = min(c[i][j], c[i][k] + c[k][j]); } for(int i = 0; i < n; i++) if(c[i][i] <= 0) return true; return false; }; int lb = 0, rb = INF; while(lb <= rb) { int mb = (lb + rb) / 2; if(ok(mb)) lb = mb + 1; else rb = mb - 1; } cout << rb << '\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...