Submission #367989

#TimeUsernameProblemLanguageResultExecution timeMemory
367989parsabahramiTravelling Merchant (APIO17_merchant)C++17
100 / 100
219 ms3564 KiB
// Call my Name and Save me from The Dark #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; #define SZ(x) (int) x.size() #define F first #define S second const int N = 110, M = 9905, K = 1e3 + 10; int n, m, k, w[M], from[M], to[M], S[N][K], B[N][K]; ll dp[N][N], C[N][N]; void Fill() { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { dp[i][j] = -1e18; if (i == j) dp[i][j] = 0; } } } int check(ll x) { Fill(); for (int i = 1; i <= m; i++) { int u = from[i], v = to[i]; dp[u][v] = max(dp[u][v], -w[i] * x); } for (int p = 1; p <= n; p++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) dp[i][j] = min((ll) 1e18, max(dp[i][j], dp[i][p] + dp[p][j])); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) dp[i][j] += C[i][j]; for (int p = 1; p <= n; p++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) dp[i][j] = min((ll) 1e18, max(dp[i][j], dp[i][p] + dp[p][j])); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (i != j && dp[i][j] + dp[j][i] >= 0) return 1; return 0; } int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) scanf("%d%d", &B[i][j], &S[i][j]); } for (int i = 1; i <= m; i++) { scanf("%d%d%d", &from[i], &to[i], &w[i]); } for (int u = 1; u <= n; u++) { for (int v = 1; v <= n; v++) { for (int i = 1; i <= k; i++) if (~B[u][i] && ~S[v][i]) C[u][v] = max(C[u][v], (ll) S[v][i] - B[u][i]); } } ll l = 0, r = 1e9; while (r - l > 1) { ll mid = (l + r) >> 1; if (check(mid)) l = mid; else r = mid; } printf("%lld\n", l); return 0; }

Compilation message (stderr)

merchant.cpp: In function 'int main()':
merchant.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |     scanf("%d%d%d", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:48:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |         for (int j = 1; j <= k; j++) scanf("%d%d", &B[i][j], &S[i][j]);
      |                                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |         scanf("%d%d%d", &from[i], &to[i], &w[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...