Submission #566772

#TimeUsernameProblemLanguageResultExecution timeMemory
566772benjaminkleynIdeal city (IOI12_city)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; map<pair<int,int>, bool> exists; map<pair<int,int>, int> node_of; int size[100000]; int sub_size[100000] = {0}; bool vis[100000]; int dfs(pair<int,int> u) { vis[node_of[u]] = true; int cur_x = u.first; sub_size[node_of[u]] = size[node_of[u]]; while (exists[{++cur_x, u.second}]); while (exists[{--cur_x, u.second}]) { if (exists[{cur_x, u.second - 1}]) if (!vis[node_of[{cur_x, u.second - 1}]]) sub_size[node_of[u]] += dfs({cur_x, u.second - 1}); if (exists[{cur_x, u.second + 1}]) if (!vis[node_of[{cur_x, u.second + 1}]]) sub_size[node_of[u]] += dfs({cur_x, u.second + 1}); } return sub_size[node_of[u]]; } int solve(int N, int *X, int *Y) { exists.clear(); node_of.clear(); for (int i = 0; i < N; i++) exists[{X[i], Y[i]}] = true; int node = -1; for (int i = 0; i < N; i++) { if (node_of[{X[i], Y[i]}] != 0) continue; node_of[{X[i], Y[i]}] = ++node; int cur_x = X[i]; while (exists[{--cur_x, Y[i]}]) node_of[{cur_x, Y[i]}] = node; cur_x = X[i]; while (exists[{++cur_x, Y[i]}]) node_of[{cur_x, Y[i]}] = node; } memset(size, 0, node); memset(sub_size, 0, node); memset(vis, false, node); for (int i = 0; i < N; i++) size[node_of[{X[i], Y[i]}]]++; dfs({X[0], Y[0]}); ll res = 0; for (int i = 0; i < node; i++) res += sub_size[i] * (N - sub_size[i]); return res; } int DistanceSum(int N, int *X, int *Y) { return solve(N, X, Y) + solve(N, Y, X); }

Compilation message (stderr)

city.cpp: In function 'int dfs(std::pair<int, int>)':
city.cpp:15:28: error: reference to 'size' is ambiguous
   15 |     sub_size[node_of[u]] = size[node_of[u]];
      |                            ^~~~
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 city.cpp:1:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
city.cpp:7:5: note:                 'int size [100000]'
    7 | int size[100000];
      |     ^~~~
city.cpp: In function 'int solve(int, int*, int*)':
city.cpp:52:12: error: reference to 'size' is ambiguous
   52 |     memset(size, 0, node);
      |            ^~~~
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 city.cpp:1:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
city.cpp:7:5: note:                 'int size [100000]'
    7 | int size[100000];
      |     ^~~~
city.cpp:57:9: error: reference to 'size' is ambiguous
   57 |         size[node_of[{X[i], Y[i]}]]++;
      |         ^~~~
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 city.cpp:1:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
city.cpp:7:5: note:                 'int size [100000]'
    7 | int size[100000];
      |     ^~~~