Submission #551456

#TimeUsernameProblemLanguageResultExecution timeMemory
551456Ai7081Travelling Merchant (APIO17_merchant)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define long long long #define st first #define nd second const int N = 105; const int K = 1005; struct data{ long x, t; data() {} data(long x, long t) : x(x), t(t) {} bool operator < (const data &o) const { if (!t) return true; if (!o.t) return false; if (x == 0 && o.x == 0) return t < o.t; return x*o.t < t*o.x; } bool operator > (const data &o) const {return !(*this < o);} data operator + (const data &o) {return data(x+o.x, t+o.t);} void operator += (const data &o) {x+=o.x; t+=o.t;} }; struct node{ data val; long v; bool operator < (const node &o) const {return val > o.val;} }; long n, m, k, b[N][K], s[N][K]; data dis[N][N], out; vector<pair<long, long>> adj[N]; priority_queue<node> pq; bool mark[N]; void dfs(long root, long v, long t) { dis[root][v] = {0, t}; mark[v] = true; for (int i=1; i<=k; i++) { if (root == v) break; if (b[root][i]!=-1 && s[v][i]!=-1) dis[root][v] = max(dis[root][v], {s[v][i]-b[root][i], t}); } for (auto [to, cost] : adj[v]) if (!mark[to]) dfs(root, to, t+cost); } int main() { scanf(" %lld %lld %lld", &n, &m, &k); for (int i=1; i<=n; i++) { for (int j=1; j<=k; j++) scanf(" %lld", &b[i][j]); for (int j=1; j<=k; j++) scanf(" %lld", &s[i][j]); } while (m--) { long x, y, z; scanf(" %lld %lld %lld", &x, &y, &z); adj[x].push_back({y, z}); } for (int i=1; i<=n; i++) fill_n(mark, N, false), dfs(i, i, 0); // for (int i=1; i<=n; i++) { // printf("dis %d : ", i); // for (int j=1; j<=n; j++) printf("(%lld %lld) ", dis[i][j].x, dis[i][j].t); // printf("\n"); // } for (int s=1; s<=n; s++) { for (int i=1; i<=n; i++) { for (int j=1; j<=n; j++) if (dis[i][s].t && dis[s][j].t) { dis[i][j] = max(dis[i][j], dis[i][s] + dis[s][j]); } } } for (int i=1; i<=n; i++) out = max(out, dis[i][i]); printf("%lld %lld\n", out.x, out.t); printf("%lld", out.t ? out.x/out.t : 0); 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:26:5: error: reference to 'data' is ambiguous
   26 |     data val;
      |     ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from merchant.cpp:1:
/usr/include/c++/10/bits/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:310:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:300:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:290:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
merchant.cpp:10:8: note:                 'struct data'
   10 | struct data{
      |        ^~~~
merchant.cpp: In member function 'bool node::operator<(const node&) const':
merchant.cpp:28:51: error: 'val' was not declared in this scope
   28 |     bool operator < (const node &o) const {return val > o.val;}
      |                                                   ^~~
merchant.cpp:28:59: error: 'const struct node' has no member named 'val'
   28 |     bool operator < (const node &o) const {return val > o.val;}
      |                                                           ^~~
merchant.cpp: At global scope:
merchant.cpp:32:1: error: reference to 'data' is ambiguous
   32 | data dis[N][N], out;
      | ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from merchant.cpp:1:
/usr/include/c++/10/bits/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:310:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:300:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:290:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
merchant.cpp:10:8: note:                 'struct data'
   10 | struct data{
      |        ^~~~
merchant.cpp: In function 'void dfs(long long int, long long int, long long int)':
merchant.cpp:38:5: error: 'dis' was not declared in this scope; did you mean 'dfs'?
   38 |     dis[root][v] = {0, t};
      |     ^~~
      |     dfs
merchant.cpp: In function 'int main()':
merchant.cpp:69:42: error: 'dis' was not declared in this scope; did you mean 'dfs'?
   69 |             for (int j=1; j<=n; j++) if (dis[i][s].t && dis[s][j].t) {
      |                                          ^~~
      |                                          dfs
merchant.cpp:75:30: error: 'out' was not declared in this scope
   75 |     for (int i=1; i<=n; i++) out = max(out, dis[i][i]);
      |                              ^~~
merchant.cpp:75:45: error: 'dis' was not declared in this scope; did you mean 'dfs'?
   75 |     for (int i=1; i<=n; i++) out = max(out, dis[i][i]);
      |                                             ^~~
      |                                             dfs
merchant.cpp:76:27: error: 'out' was not declared in this scope
   76 |     printf("%lld %lld\n", out.x, out.t);
      |                           ^~~
merchant.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     scanf(" %lld %lld %lld", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:50:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         for (int j=1; j<=k; j++) scanf(" %lld", &b[i][j]);
      |                                  ~~~~~^~~~~~~~~~~~~~~~~~~
merchant.cpp:51:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         for (int j=1; j<=k; j++) scanf(" %lld", &s[i][j]);
      |                                  ~~~~~^~~~~~~~~~~~~~~~~~~
merchant.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         scanf(" %lld %lld %lld", &x, &y, &z);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~