제출 #57851

#제출 시각아이디문제언어결과실행 시간메모리
57851Jeez여행하는 상인 (APIO17_merchant)C++14
100 / 100
278 ms2656 KiB
#include <iostream> using namespace std; typedef long long ll; const ll INF = 1e10; const int MAX_N = 100 + 9; const int MAX_K = 1000 + 9; int n, m, K; ll buy[MAX_N][MAX_K], sell[MAX_N][MAX_K]; ll w[MAX_N][MAX_N], dist[MAX_N][MAX_N], profit[MAX_N][MAX_N]; ll g[MAX_N][MAX_N]; void read(){ cin >> n >> m >> K; for(int i = 1; i <= n; i++) for(int j = 1; j <= K; j++) cin >> buy[i][j] >> sell[i][j]; for(int i = 0; i < m; i++){ int u, v; ll w; cin >> u >> v >> w; dist[u][v] = w; } } void init(){ for(int i = 1; i < MAX_N; i++){ for(int j = 1; j < MAX_N; j++) dist[i][j] = INF; dist[i][i] = 0; } } void floyd(){ 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]); } bool check(ll rat){ for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) g[i][j] = profit[i][j] - rat * dist[i][j]; for(int k = 1; k <= n; k++) for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) if(i != j && dist[i][k] < INF && dist[k][j] < INF) g[i][j] = max(g[i][j], g[i][k] + g[k][j]); for(int i = 1; i <= n; i++) for(int j = i + 1; j <= n; j++) if(g[i][j] + g[j][i] >= 0 && dist[i][j] < INF && dist[j][i] < INF) return true; return false; } void solve(){ for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) for(int k = 1; k <= K; k++){ if(sell[j][k] == -1 || buy[i][k] == -1) continue; profit[i][j] = max(profit[i][j], sell[j][k] - buy[i][k]); } ll lo = 1, hi = 1e9 + 1, mid, ans = 0; while(lo <= hi){ mid = (lo + hi) / 2; if(check(mid)){ ans = mid; lo = mid + 1; } else hi = mid - 1; } cout << ans << '\n'; } int main() { init(); read(); floyd(); solve(); 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...