제출 #118936

#제출 시각아이디문제언어결과실행 시간메모리
118936Mahdi_Jfri여행하는 상인 (APIO17_merchant)C++14
0 / 100
80 ms3084 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back const int maxn = 1e2 + 20; const int maxm = 1e4 + 20; const int maxk = 1e3 + 20; int b[maxn][maxk] , s[maxn][maxk]; int d[maxn][maxn] , best[maxn][maxn] , n; ll res[maxn][maxn]; bool check(ll x) { for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) res[i][j] = d[i][j] * x - best[i][j]; for(int k = 0; k < n; k++) for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) res[i][j] = min(res[i][j] , res[i][k] + res[k][j]); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(res[i][j] + res[j][i] <= 0) return 1; return 0; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int m , k; 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]; memset(d , 63 , sizeof d); for(int i = 0; i < m; i++) { int a , b , c; cin >> a >> b >> c; a-- , b--; d[a][b] = min(d[a][b] , c); } 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++) for(int j = 0; j < n; j++) for(int ind = 0; ind < k; ind++) if(b[i][ind] != -1 && s[j][ind] != -1) best[i][j] = max(best[i][j] , s[j][ind] - b[i][ind]); int l = 0 , r = 2e9; while(r - l > 1) { int m = (l + r) / 2; if(check(m)) l = m; else r = m; } cout << l << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...