Submission #531463

#TimeUsernameProblemLanguageResultExecution timeMemory
531463Alex_tz307Travelling Merchant (APIO17_merchant)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#define int long long

using namespace std;

const int64_t INF = 2e18L;

void maxSelf(int &x, int y) {
  if (x < y) {
    x = y;
  }
}

void minSelf(int64_t &x, int64_t y) {
  if (y < x) {
    x = y;
  }
}

void FloydWarshall(vector<vector<int64_t>> &d) {
  int n = d.size() - 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      for (int k = 1; k <= n; ++k) {
        minSelf(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

void testCase() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int>> b(n + 1, vector<int>(k + 1)), s(n + 1, vector<int>(k + 1));
  vector<vector<int64_t>> d(n + 1, vector<int64_t>(n + 1, INF));
  for (int u = 1; u <= n; ++u) {
    for (int i = 1; i <= k; ++i) {
      cin >> b[u][i] >> s[u][i];
    }
  }
  for (int i = 0; i < m; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    d[u][v] = w;
  }
  FloydWarshall(d);
  vector<vector<int>> profit(n + 1, vector<int>(n + 1));
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      for (int p = 1; p <= k; ++p) {
        if (b[i][p] != -1 && s[j][p] != -1) {
          maxSelf(profit[i][j], s[j][p] - b[i][p]);
        }
      }
    }
  }
  int l = 1, r = 1e9;
  while (l <= r) {
    int mid = (l + r) / 2;
    vector<vector<int64_t>> dp(n + 1, vector<int64_t>(n + 1));
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        dp[i][j] = (int64_t)mid * min(d[i][j], INF / mid) - profit[i][j];
      }
    }
    FloydWarshall(dp);
    bool ok = false;
    for (int v = 1; v <= n; ++v) {
      if (dp[v][v] <= 0) {
        ok = true;
      }
    }
    if (ok) {
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  cout << r << '\n';
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int tests = 1;
  for (int tc = 0; tc < tests; ++tc) {
    testCase();
  }
  return 0;
}

Compilation message (stderr)

merchant.cpp: In function 'void testCase()':
merchant.cpp:63:57: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type&, long long int)'
   63 |         dp[i][j] = (int64_t)mid * min(d[i][j], INF / mid) - profit[i][j];
      |                                                         ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from merchant.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
merchant.cpp:63:57: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   63 |         dp[i][j] = (int64_t)mid * min(d[i][j], INF / mid) - profit[i][j];
      |                                                         ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from merchant.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
merchant.cpp:63:57: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   63 |         dp[i][j] = (int64_t)mid * min(d[i][j], INF / mid) - profit[i][j];
      |                                                         ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from merchant.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
merchant.cpp:63:57: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   63 |         dp[i][j] = (int64_t)mid * min(d[i][j], INF / mid) - profit[i][j];
      |                                                         ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from merchant.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
merchant.cpp:63:57: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   63 |         dp[i][j] = (int64_t)mid * min(d[i][j], INF / mid) - profit[i][j];
      |                                                         ^