Submission #698890

#TimeUsernameProblemLanguageResultExecution timeMemory
698890nguyentunglamTravelling Merchant (APIO17_merchant)C++17
0 / 100
35 ms1996 KiB
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; const int N = 110; int s[N][N], b[N][N]; int n, m, k; int cnt[2][N][N]; long long f[2][N][N]; bool in[2][N][N]; queue<tuple<int, int, int> > q; vector<pair<int, int> > adj[N]; bool check(int mid) { for(int i = 1; i <= 1; i++) { memset(f, -127, sizeof(f)); memset(cnt, 0, sizeof(cnt)); f[0][0][i] = 0; q.push({0, 0, i}); while (!q.empty()) { auto [exit, carry, u] = q.front(); q.pop(); in[exit][carry][u] = 0; cnt[exit][carry][u]++; if (cnt[exit][carry][u] >= 5) return 1; if (carry) { if (s[u][carry] != -1 && f[exit][0][u] < f[exit][carry][u] + s[u][carry]) { f[exit][0][u] = f[exit][carry][u] + s[u][carry]; if (!in[exit][0][u]) q.push({exit, 0, u}), in[exit][0][u] = 1; } } if (!carry) { for(int j = 1; j <= k; j++) { if (b[u][j] != -1 && f[exit][j][u] < f[exit][carry][u] - b[u][j]) { f[exit][j][u] = f[exit][carry][u] - b[u][j]; if (!in[exit][j][u]) q.push({exit, j, u}), in[exit][j][u] = 1; } } } for(auto &[v, w] : adj[u]) { int _e = exit | 1; if (f[_e][carry][v] < f[exit][carry][u] - w * mid) { f[_e][carry][v] = f[exit][carry][u] - w * mid; if (!in[_e][carry][v]) q.push({_e, carry, v}), in[exit][carry][v] = 1; } } } if (f[1][0][i] >= 0) return 1; } return 0; } int main() { #define task "" cin.tie(0) -> sync_with_stdio(0); if (fopen ("task.inp", "r")) { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); } if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } cin >> n >> m >> k; for(int i = 1; i <= n; i++) for(int j = 1; j <= k; j++) cin >> b[i][j] >> s[i][j]; while (m--) { int u, v, w; cin >> u >> v >> w; adj[u].emplace_back(v, w); } int l = 1, r = 1e9, res = 0; while (l <= r) { int mid = l + r >> 1; if (check(mid)) { l = mid + 1; res = mid; } else r = mid - 1; } cout << res; }

Compilation message (stderr)

merchant.cpp: In function 'int main()':
merchant.cpp:71:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   71 |         int mid = l + r >> 1;
      |                   ~~^~~
merchant.cpp:56:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:57:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:60:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:61:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...