Submission #306189

#TimeUsernameProblemLanguageResultExecution timeMemory
306189jovan_bTravelling Merchant (APIO17_merchant)C++17
0 / 100
208 ms3448 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; ll buy[105][1005]; ll sell[105][1005]; ll dist[1005][1005]; ll graf[1005][1005]; ll prof[1005][1005]; ll tren[1005][1005]; const ll INF = 1000000000000000LL; int n; bool check(ll val){ for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ tren[i][j] = - prof[i][j] + dist[i][j]*val; // cout << i << " " << j << " " << tren[i][j] << endl; } } for(int k=1; k<=n; k++){ for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ tren[i][j] = min(tren[i][j], tren[i][k] + tren[k][j]); } } } for(int k=1; k<=n; k++){ for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ if(tren[i][j] > tren[i][k] + tren[k][j]) return 1; } } } return 0; } int main(){ ios_base::sync_with_stdio(false), cin.tie(0); cout.precision(0); cout << fixed; int m, K; cin >> n >> m >> K; for(int i=1; i<=n; i++){ for(int j=1; j<=K; j++){ cin >> buy[i][j]; cin >> sell[i][j]; //buy[i][j] *= 2; //sell[i][j] *= 2; } } for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ dist[i][j] = graf[i][j] = INF; } dist[i][i] = graf[i][i] = 0; } for(int i=1; i<=m; i++){ ll a, b, c; cin >> a >> b >> c; //c *= 2; dist[a][b] = graf[a][b] = min(graf[a][b], c); } 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++){ if(i == j) continue; for(int k=1; k<=K; k++){ if(buy[i][k]+1 && sell[j][k]+1) prof[i][j] = max(prof[i][j], sell[j][k]-buy[i][k]); } //cout << i << " " << j << " za " << prof[i][j] << endl; } } ld res = 0, l = 1, r = 2000000000, tries = 100; while(tries--){ ld mid = (l+r)/2; if(check(mid)){ res = mid; l = mid+0.001; } else r = mid-0.001; } res += 0.001; ll pr = res; cout << pr; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...