Submission #639717

#TimeUsernameProblemLanguageResultExecution timeMemory
639717ghostwriterTravelling Merchant (APIO17_merchant)C++14
100 / 100
84 ms3388 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debug.h> #endif #define st first #define nd second #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define mtp make_tuple #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef string str; template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i)) #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i)) #define EACH(i, x) for (auto &(i) : (x)) #define WHILE while #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } /* Tran The Bao CTL - Da Lat Cay ngay cay dem nhung deo duoc cong nhan */ const ll oo = 1e18; const int N = 105; const int K = 1005; int n, m, k, b[N][K], s[N][K], c[N][N]; ll d[N][N], g[N][N]; bool check(int x) { FOR(i, 1, n) FOR(j, 1, n) { if (i == j) { g[i][j] = -oo; continue; } if (d[i][j] == oo) { g[i][j] = -oo; continue; } g[i][j] = -x * d[i][j] + c[i][j]; } FOR(z, 1, n) FOR(i, 1, n) FOR(j, 1, n) g[i][j] = max(g[i][j], g[i][z] + g[z][j]); FOR(i, 1, n) if (g[i][i] >= 0) return 1; return 0; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); // freopen(file".inp", "r", stdin); // freopen(file".out", "w", stdout); cin >> n >> m >> k; FOR(i, 1, n) FOR(j, 1, k) cin >> b[i][j] >> s[i][j]; FOR(i, 1, n) FOR(j, 1, n) d[i][j] = (i == j? 0 : oo); FOR(i, 1, m) { int v, w, t; cin >> v >> w >> t; d[v][w] = t; } FOR(z, 1, n) FOR(i, 1, n) FOR(j, 1, n) d[i][j] = min(d[i][j], d[i][z] + d[z][j]); FOR(i, 1, n) FOR(j, 1, n) FOR(z, 1, k) if (b[i][z] != -1 && s[j][z] != -1) c[i][j] = max(c[i][j], -b[i][z] + s[j][z]); int l = 1, r = 1e9, ans = 0; WHILE(l <= r) { int mid = l + (r - l) / 2; if (check(mid)) { ans = mid; l = mid + 1; } else r = mid - 1; } cout << ans; return 0; } /* 4 5 2 10 9 5 2 6 4 20 15 9 7 10 9 -1 -1 16 11 1 2 3 2 3 3 1 4 1 4 3 1 3 1 1 */

Compilation message (stderr)

merchant.cpp: In function 'bool check(int)':
merchant.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
merchant.cpp:42:2: note: in expansion of macro 'FOR'
   42 |  FOR(i, 1, n)
      |  ^~~
merchant.cpp:24:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
merchant.cpp:43:2: note: in expansion of macro 'FOR'
   43 |  FOR(j, 1, n) {
      |  ^~~
merchant.cpp:24:31: warning: unnecessary parentheses in declaration of 'z' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
merchant.cpp:54:2: note: in expansion of macro 'FOR'
   54 |  FOR(z, 1, n)
      |  ^~~
merchant.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
merchant.cpp:55:2: note: in expansion of macro 'FOR'
   55 |  FOR(i, 1, n)
      |  ^~~
merchant.cpp:24:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
merchant.cpp:56:2: note: in expansion of macro 'FOR'
   56 |  FOR(j, 1, n)
      |  ^~~
merchant.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
merchant.cpp:58:2: note: in expansion of macro 'FOR'
   58 |  FOR(i, 1, n)
      |  ^~~
merchant.cpp: In function 'int main()':
merchant.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
merchant.cpp:68:5: note: in expansion of macro 'FOR'
   68 |     FOR(i, 1, n)
      |     ^~~
merchant.cpp:24:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
merchant.cpp:69:5: note: in expansion of macro 'FOR'
   69 |     FOR(j, 1, k)
      |     ^~~
merchant.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
merchant.cpp:71:5: note: in expansion of macro 'FOR'
   71 |     FOR(i, 1, n)
      |     ^~~
merchant.cpp:24:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
merchant.cpp:72:5: note: in expansion of macro 'FOR'
   72 |     FOR(j, 1, n)
      |     ^~~
merchant.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
merchant.cpp:74:5: note: in expansion of macro 'FOR'
   74 |     FOR(i, 1, m) {
      |     ^~~
merchant.cpp:24:31: warning: unnecessary parentheses in declaration of 'z' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
merchant.cpp:79:5: note: in expansion of macro 'FOR'
   79 |     FOR(z, 1, n)
      |     ^~~
merchant.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
merchant.cpp:80:5: note: in expansion of macro 'FOR'
   80 |     FOR(i, 1, n)
      |     ^~~
merchant.cpp:24:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
merchant.cpp:81:5: note: in expansion of macro 'FOR'
   81 |     FOR(j, 1, n)
      |     ^~~
merchant.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
merchant.cpp:83:5: note: in expansion of macro 'FOR'
   83 |     FOR(i, 1, n)
      |     ^~~
merchant.cpp:24:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
merchant.cpp:84:5: note: in expansion of macro 'FOR'
   84 |     FOR(j, 1, n)
      |     ^~~
merchant.cpp:24:31: warning: unnecessary parentheses in declaration of 'z' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
merchant.cpp:85:2: note: in expansion of macro 'FOR'
   85 |  FOR(z, 1, k)
      |  ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...