Submission #1191913

#TimeUsernameProblemLanguageResultExecution timeMemory
1191913mannshah1211Travelling Merchant (APIO17_merchant)C++20
Compilation error
0 ms0 KiB
/** * author: tourist * created: 25.04.2025 19:27:44 **/ #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "algo/debug.h" #else #define debug(...) 42 #endif const long long inf = (long long) 1e18; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, k; cin >> n >> m >> k; vector<vector<int>> buy(n, vector<int>(k)), sell(n, vector<int>(k)); for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { cin >> buy[i][j] >> sell[i][j]; } } vector<vector<long long>> profit(n, vector<long long>(n)), dist(n, vector<long long>(n, inf)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int item = 0; item < k; item++) { if (buy[i][item] != -1 && sell[j][item] != -1) { profit[i][j] = max(profit[i][j], int64_t(sell[j][item] - buy[i][item])); } } } } for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; long long t; cin >> t; --u; --v; dist[u][v] = min(dist[u][v], t); } for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } } auto Check = [&](int mid) { vector<vector<long long>> d(n, vector<long long>(n, inf)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (dist[i][j] != inf) { d[i][j] = int64_t(mid) * int64_t(dist[i][j]) - profit[i][j]; } } } for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); if (i == j && d[i][j] <= 0) { return true; } } } } return false; }; int low = 0, high = 1e9, ans = -1; while (low <= high) { int mid = (low + high) >> 1; if (Check(mid)) { ans = mid; low = mid + 1; } else { high = mid - 1; } } cout << ans << '\n'; return 0; }

Compilation message (stderr)

merchant.cpp: In function 'int main()':
merchant.cpp:33:29: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&, int64_t)'
   33 |           profit[i][j] = max(profit[i][j], int64_t(sell[j][item] - buy[i][item]));
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from merchant.cpp:5:
/usr/include/c++/11/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
merchant.cpp:33:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t' {aka 'long int'})
   33 |           profit[i][j] = max(profit[i][j], int64_t(sell[j][item] - buy[i][item]));
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from merchant.cpp:5:
/usr/include/c++/11/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
merchant.cpp:33:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t' {aka 'long int'})
   33 |           profit[i][j] = max(profit[i][j], int64_t(sell[j][item] - buy[i][item]));
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from merchant.cpp:5:
/usr/include/c++/11/bits/stl_algo.h:3461:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3461 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3461:5: note:   template argument deduction/substitution failed:
merchant.cpp:33:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   33 |           profit[i][j] = max(profit[i][j], int64_t(sell[j][item] - buy[i][item]));
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from merchant.cpp:5:
/usr/include/c++/11/bits/stl_algo.h:3467:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3467 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3467:5: note:   template argument deduction/substitution failed:
merchant.cpp:33:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   33 |           profit[i][j] = max(profit[i][j], int64_t(sell[j][item] - buy[i][item]));
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~