Submission #197999

#TimeUsernameProblemLanguageResultExecution timeMemory
197999stefdascaTravelling Merchant (APIO17_merchant)C++14
0 / 100
459 ms3064 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]; ll dp[102], dpaux[102]; bool viz[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]; } ll ans = 0; 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 && buy[i][x] != -1 && sell[j][x] != -1) maxdif[i][j] = max(maxdif[i][j], sell[j][x] - buy[i][x]); } for(int start = 1; start <= n; ++start) { memset(dp, 0, sizeof(dp)); memset(dpaux, 0, sizeof(dpaux)); memset(viz, 0, sizeof(viz)); viz[start] = 1; for(int i = 1; i <= n+1; ++i) { for(int j = 1; j <= n; ++j) if(viz[j]) for(int k = 1; k <= n; ++k) { if(j != k && rf[j][k]) { if(!viz[k] || dp[k] == 0) dp[k] = (dp[j] + maxdif[j][k]), dpaux[k] = dpaux[j] + rf[j][k], viz[k] = 1; else if((dp[j] + maxdif[j][k]) * dpaux[k] > (dpaux[j] + rf[j][k]) * dp[k]) viz[k] = 1, dp[k] = (dp[j] + maxdif[j][k]), dpaux[k] = dpaux[j] + rf[j][k]; } } if(dpaux[start]) ans = max(ans, dp[start] / dpaux[start]); } ans = max(ans, dp[start] / dpaux[start]); } 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...