Submission #399019

#TimeUsernameProblemLanguageResultExecution timeMemory
399019Osama_AlkhodairyTravelling Merchant (APIO17_merchant)C++17
100 / 100
100 ms4232 KiB
#include <bits/stdc++.h> using namespace std; #define finish(x) return cout << x << endl, 0 #define ll long long const int N = 101; const int K = 1001; const ll INF = (ll)1e18; int n, m, k; ll B[N][K], S[N][K], mx[N][N], dist[N][N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); for(int i = 1 ; i < N ; i++){ for(int j = 1 ; j < N ; j++){ dist[i][j] = INF; } } cin >> n >> m >> k; for(int i = 1 ; i <= n ; i++){ for(int j = 1 ; j <= k ; j++){ cin >> B[i][j] >> S[i][j]; } } for(int i = 0 ; i < m ; i++){ int x, y, z; cin >> x >> y >> z; dist[x][y] = z; } 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]); } } } for(int i = 1 ; i <= n ; i++){ for(int j = 1 ; j <= n ; j++){ for(int p = 1 ; p <= k ; p++){ if(B[i][p] != -1 && S[j][p] != -1){ mx[i][j] = max(mx[i][j], S[j][p] - B[i][p]); } } } } int l = 0, r = (int)1e9; while(l <= r){ int mid = (l + r) / 2; vector <vector <ll> > c(n + 1, vector <ll>(n + 1)); for(int i = 1 ; i <= n ; i++){ for(int j = 1 ; j <= n ; j++){ c[i][j] = mx[i][j] - (dist[i][j] == INF ? INF : dist[i][j] * mid); } } for(int k = 1 ; k <= n ; k++){ for(int i = 1 ; i <= n ; i++){ for(int j = 1 ; j <= n ; j++){ c[i][j] = max(c[i][j], c[i][k] + c[k][j]); } } } bool ok = 0; for(int i = 1 ; i <= n ; i++){ if(c[i][i] >= 0) ok = 1; } if(ok) l = mid + 1; else r = mid - 1; } cout << r << 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...