Submission #492504

#TimeUsernameProblemLanguageResultExecution timeMemory
492504MahfelTravelling Merchant (APIO17_merchant)C++17
0 / 100
442 ms2200 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll MXN = 120 , MXM = 10000 , MXK = 1020 , Inf = 1e16 + 7; const double EPS = 1e-9; ll n,m,k; ll profit[MXN][MXN] , dis[MXN][MXN]; ll buy[MXN][MXK] , sell[MXN][MXK]; double gr[MXN][MXN]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); 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]; // if(buy[i][j] == -1) buy[i][j] = Inf; // if(sell[i][j] == -1) sell[i][j] = -Inf; } } for(int i = 1 ; i <= n ; i++) { for(int j = 1 ; j <= n ; j++) { dis[i][j] = Inf; } dis[i][i] = 0; } for(int i = 0 ; i < m ; i++) { ll v,u,w; cin >> v >> u >> w; dis[v][u] = w; } for(int k = 1 ; k <= n ; k++) { for(int i = 1 ; i <= n ; i++) { for(int j = 1 ; j <= n ; j++) { dis[i][j] = min(dis[i][j] , dis[i][k] + dis[k][j]); } } } for(int i = 1 ; i <= n ; i++) { for(int j = 1 ; j <= n ; j++) { for(int x = 1 ; x <= k ; x++) { if(sell[j][x] != -1 && buy[i][x] != -1) profit[i][j] = max(profit[i][j] , sell[j][x] - buy[i][x]); } } } double l = 0 , r = 10000000000; for(int itr = 0 ; itr < 100 ; itr++) { double m = (l+r)/2.0; for(int i = 1 ; i <= n ; i++) { for(int j = 1 ; j <= n ; j++) { gr[i][j] = double(dis[i][j])*m - double(profit[i][j]); if(i == j) gr[i][j] = Inf; } } for(int k = 1 ; k <= n ; k++) { for(int i = 1 ; i <= n ; i++) { for(int j = 1 ; j <= n ; j++) { // gr[i][j] = min(gr[i][j] , gr[i][k] + gr[k][j]); if(gr[i][k] + gr[k][j] < gr[i][j]-EPS) { gr[i][j] = gr[i][k] + gr[k][j]; } if(gr[i][j] < -Inf) gr[i][j] = -Inf; } } } bool ok = 0; for(int i = 1 ; i <= n ; i++) { if(gr[i][i] < 0) { ok = 1; break; } } if(ok) { l = m; } else { r = m; } } printf("%.0lf\n" , 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...