Submission #197960

#TimeUsernameProblemLanguageResultExecution timeMemory
197960stefdascaTravelling Merchant (APIO17_merchant)C++14
12 / 100
231 ms5008 KiB
#include<bits/stdc++.h> #define god dimasi5eks #pragma GCC optimize("O3") #define fi first #define se second #define pb push_back #define pf push_front #define mod 1000000007 #define dancila 3.14159265359 #define eps 1e-9 // #define fisier 1 using namespace std; typedef long long ll; int n, m, k, buy[102][1002], sell[102][1002], rf[102][102]; int maxdif[102][102]; int main() { #ifdef fisier ifstream f("input.in"); ofstream g("output.out"); #endif ios_base::sync_with_stdio(false); 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]; } for(int i = 1; i <= m; ++i) { int a, b, c; cin >> a >> b >> c; rf[a][b] = c; } for(int k = 1; k <= n; ++k) for(int i = 1; i <= n; ++i) for(int j = 1; j <= n; ++j) if(i != j && rf[i][k] && rf[k][j]) { if(rf[i][j] == 0 || rf[i][j] > rf[i][k] + rf[k][j]) rf[i][j] = rf[i][k] + rf[k][j]; } for(int i = 1; i <= n; ++i) for(int j = 1; j <= n; ++j) if(i != j && rf[i][j]) for(int x = 1; x <= k; ++x) if(i != j && rf[i][j] && buy[i][x] != -1 && sell[j][x] != -1) maxdif[i][j] = max(maxdif[i][j], sell[j][x] - buy[i][x]); ll ans = 0; for(int start = 1; start <= n; ++start) { int states = 100000 / n; deque<pair<int, pair<ll, int> > >d; d.pb({start, {0, 0}}); while(!d.empty()) { --states; pair<int, pair<ll, int> > nod = d[0]; d.pop_front(); for(int vec = 1; vec <= n; ++vec) { if(vec != nod.fi && rf[nod.fi][vec]) { if(vec == start) { ll rap = (nod.se.fi + maxdif[nod.fi][vec]) / (nod.se.se + rf[nod.fi][vec]); ans = max(ans, rap); } else d.pb({vec, {nod.se.fi + maxdif[nod.fi][vec], nod.se.se + rf[nod.fi][vec]}}); } } if(states == 0) break; } } cout << ans; 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...