Submission #306210

#TimeUsernameProblemLanguageResultExecution timeMemory
306210jovan_bTravelling Merchant (APIO17_merchant)C++17
100 / 100
736 ms4216 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]; ld tren[1005][1005]; const ll INF = 1000000000000LL; int n; bool cmp(ld a, ld b){ return abs(a-b) > 0.0001; } bool check(ld val){ for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ if(dist[i][j] == INF) tren[i][j] = INF; else tren[i][j] = - prof[i][j] + (1.0*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] && cmp(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(10); 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 = 1000000000; int tries = 60; while(tries--){ ld mid = (l+r)/2; if(check(mid)){ res = mid; l = mid; } else r = mid; } res += 0.001; ll rr = res; cout << rr << "\n"; 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...