제출 #656907

#제출 시각아이디문제언어결과실행 시간메모리
656907Melika0gh여행하는 상인 (APIO17_merchant)C++17
100 / 100
140 ms4052 KiB
#include<bits/stdc++.h> using namespace std; typedef long long int ll; const ll inf = 1121272678990188431; const int maxn = 1e2+10, maxk = 1e3+10; ll b[maxn][maxk], s[maxn][maxk], dis[maxn][maxn], new_w[maxn][maxn], max_ben[maxn][maxn]; int n, m, k; void FloydWarshall(ll d[maxn][maxn]) { for(int w = 0; w < n; w++) for(int v = 0; v < n; v++) for(int u = 0; u < n; u++) d[v][u] = min(d[v][u], d[v][w] + d[w][u]); return; } void CalcBen() { for(int v = 0; v < n; v++) for(int u = 0; u < n; u++) for(int l = 0; l < k; l++) if(b[v][l] != -1 && s[u][l] != -1) max_ben[v][u] = max(max_ben[v][u], s[u][l] - b[v][l]); return; } bool Valid(ll x) { for(int v = 0; v < n; v++) { for(int u = 0; u < n; u++) { if(dis[v][u] == inf) new_w[v][u] = inf; else new_w[v][u] = x * dis[v][u] - max_ben[v][u]; } } FloydWarshall(new_w); for(int v = 0; v < n; v++) if(new_w[v][v] <= 0) return true; return false; } ll Bs(ll l, ll r) { if((r - l) <= 1) return l; ll mid = (l + r) / 2; if(Valid(mid)) return Bs(mid, r); else return Bs(l, mid); } int main() { cin >> n >> m >> k; for(int i = 0; i < n; i++) for(int j = 0; j < k; j++) cin >> b[i][j] >> s[i][j]; for(int i = 0; i < n; i++) fill(dis[i], dis[i] + n, inf); for(int i = 0; i < m; i++) { int v, u; ll w; cin >> v >> u >> w; v--, u--; dis[v][u] = w; } FloydWarshall(dis); CalcBen(); ll ans = Bs(0, 1e9+10); cout << ans << '\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...