Submission #370056

#TimeUsernameProblemLanguageResultExecution timeMemory
37005679brueTravelling Merchant (APIO17_merchant)C++14
100 / 100
120 ms4204 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, m, k; vector<pair<int, ll> > link[102]; ll buy[102][1002], sell[102][1002]; ll dist[102][102]; ll profit[102][102]; ll tDist[102][102]; bool able(ll key){ for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ tDist[i][j] = profit[i][j] - key * dist[i][j]; } } for(int d=1; d<=n; d++){ for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ tDist[i][j] = max(tDist[i][j], tDist[i][d] + tDist[d][j]); } } } for(int i=1; i<=n; i++){ if(tDist[i][i] >= 0) return true; } return false; } int main(){ scanf("%d %d %d", &n, &m, &k); for(int i=1; i<=n; i++){ for(int j=1; j<=k; j++){ scanf("%lld %lld", &buy[i][j], &sell[i][j]); } } for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) dist[i][j] = 1e9; for(int i=1; i<=m; i++){ int x, y; ll z; scanf("%d %d %lld", &x, &y, &z); dist[x][y] = z; } for(int d=1; d<=n; d++){ for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ dist[i][j] = min(dist[i][j], dist[i][d] + dist[d][j]); } } } for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ for(int x=1; x<=k; x++){ if(min({sell[j][x], buy[i][x]}) == -1) continue; profit[i][j] = max(profit[i][j], sell[j][x] - buy[i][x]); } } } ll MIN = 0, MAX = 1e9, ANS = 0; while(MIN <= MAX){ ll MID = (MIN + MAX) / 2; if(able(MID)){ ANS = MID; MIN = MID+1; } else MAX = MID-1; } printf("%lld", ANS); }

Compilation message (stderr)

merchant.cpp: In function 'int main()':
merchant.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |     scanf("%d %d %d", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:40:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |             scanf("%lld %lld", &buy[i][j], &sell[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |         scanf("%d %d %lld", &x, &y, &z);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...