제출 #123691

#제출 시각아이디문제언어결과실행 시간메모리
123691nvmdava여행하는 상인 (APIO17_merchant)C++17
100 / 100
109 ms5112 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long ll d[105][105], p[105][105], t[105][105]; ll s[105][2005], b[105][2005]; int n, m, k; #define crypt 0x3f2e32d7a2f6e5c3 inline void fw(ll re[105][105]){ for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) for(int l = 1; l <= n; l++) re[j][l] = min(re[j][l], re[j][i] + re[i][l]); } bool check(ll val){ for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) t[i][j] = d[i][j] == crypt ? LLONG_MAX / 2 : - p[i][j] + min(d[i][j], LLONG_MAX / 2 / val) * val; fw(t); for(int i = 1; i <= n; i++){ if(t[i][i] <= 0) return 1; } return 0; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m>>k; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) d[i][j] = crypt; for(int i = 1; i <= n; i++){ for(int j = 1; j <= k; j++){ cin>>b[i][j]>>s[i][j]; } } while(m--){ int v, u, t; cin>>v>>u>>t; d[v][u] = t; } fw(d); for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ if(d[i][j] == 1000000001) continue; for(int l = 1; l <= k; l++){ if(b[i][l] == -1 || s[j][l] == -1) continue; p[i][j] = max(p[i][j], s[j][l] - b[i][l]); } } } long long l = 0, r = 10000000001; while(l != r){ ll m = (l + r + 1) >> 1; if(check(m)) l = m; else r = m - 1; } cout<<l; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...