Submission #373664

#TimeUsernameProblemLanguageResultExecution timeMemory
373664abra_stoneTravelling Merchant (APIO17_merchant)C++14
0 / 100
189 ms2284 KiB
#include <iostream> #include <cstdio> #define N 105 #define K 1005 using namespace std; typedef long long ll; ll n, eg, m, b[N][K], s[N][K], d[N][N], mx[N][N], mn[N][N]; bool f(ll p) { ll i, j, k; for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) mn[i][j] = p * d[i][j] - mx[i][j]; for (k = 1; k <= n; k++) { for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { if (mn[i][k] + mn[k][j] < mn[i][j]) mn[i][j] = mn[i][k] + mn[k][j]; } } } for (i = 1; i <= n; i++) if (mn[i][i] <= 0) return 1; return 0; } int main() { ll i, j, k, t1, t2, t3; cin >> n >> eg >> m; for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { scanf("%lld %lld", &b[i][j], &s[i][j]); // if (b[i][j] == -1) b[i][j] = 1e18; // if (s[i][j] == -1) s[i][j] = -1e18; } } for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) d[i][j] = 3e7; while (eg--) { scanf("%lld %lld %lld", &t1, &t2, &t3); d[t1][t2] = t3; } for (k = 1; k <= n; k++) { for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { if (d[i][k] + d[k][j] < d[i][j]) d[i][j] = d[i][k] + d[k][j]; } } } for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { for (k = 1; k <= m; k++) { if (s[j][k] != -1 && b[i][k] != -1) mx[i][j] = max(mx[i][j], s[j][k] - b[i][k]); } } } ll l = 1, r = 1e11; // while (l < r) { // ll md = (l + r + 1) / 2; // if (f(md)) l = md; // else r = md - 1; // } // cout << l << endl; ll ans = 0; while (l < r) { ll md = (l + r) / 2; if (f(md)) ans = md, l = md + 1; else r = md - 1; } cout << ans << endl; return 0; }

Compilation message (stderr)

merchant.cpp: In function 'int main()':
merchant.cpp:30:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |    scanf("%lld %lld", &b[i][j], &s[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |   scanf("%lld %lld %lld", &t1, &t2, &t3);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...