제출 #594290

#제출 시각아이디문제언어결과실행 시간메모리
594290SlavicGHighway Tolls (IOI18_highway)C++17
컴파일 에러
0 ms0 KiB
#include "highway.h" #include "bits/stdc++.h" using namespace std; using ll = long long; #define sz(a) (int)a.size() const int N = 2e5 + 10; vector<int> adj[N]; int depth[N], p[N]; void dfs(int u, int par) { p[u] = par; for(int v: adj[u]) { if(v == par) continue; depth[v] = depth[u] + 1; dfs(v, u); } } map<pair<int, int>, int> idx; int find(int start, int n, vector<int> u, vector<int> v) { idx.clear(); for(int i = 0; i < N; ++i) { adj[i].clear(); depth[i] = 0; p[i] = -1; } int m = u.size(); for(int i = 0; i < m; ++i) { adj[u[i]].push_back(v[i]); adj[v[i]].push_back(u[i]); idx[{u[i], v[i]}] = idx[{v[i], u[i]}] = i; } dfs(start, -1); int l = 1, r = N - 1, dd = -1; vector<int> c(m, 1); ll init = ask(c); while(l <= r) { int mid = l + r >> 1; vector<int> now = c; for(int j = 0; j < n; ++j) { if(depth[j] >= mid) { now[idx[{j, p[j]}]] = 0; } } if(ask(now) < init) { dd = mid; l = mid + 1; } else r = mid - 1; } vector<int> nodes; for(int i = 0; i < n; ++i) { if(depth[i] == dd) nodes.push_back(i); } assert(sz(nodes) > 0); l = 0, r = sz(nodes) - 1; int pp = -1; while(l <= r) { int mid = l + r >> 1; vector<int> now = c; for(int i = 0; i <= mid; ++i) { now[idx[{nodes[i], p[nodes[i]]}]] = 0; } if(ask(now) < init) { pp = mid; r = mid - 1; } else l = mid + 1; } assert(pp != -1); return nodes[pp]; } void find_pair(int n, vector<int> u, vector<int> v, int a, int b) { int s = find(0, n, u, v); int t = find(0, u, u, v); answer(0, s); }

컴파일 시 표준 에러 (stderr) 메시지

highway.cpp: In function 'int find(int, int, std::vector<int>, std::vector<int>)':
highway.cpp:38:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |         int mid = l + r >> 1;
      |                   ~~^~~
highway.cpp:59:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   59 |         int mid = l + r >> 1;
      |                   ~~^~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:74:28: error: no matching function for call to 'find(int, std::vector<int>&, std::vector<int>&, std::vector<int>&)'
   74 |     int t = find(0, u, u, v);
      |                            ^
highway.cpp:20:5: note: candidate: 'int find(int, int, std::vector<int>, std::vector<int>)'
   20 | int find(int start, int n, vector<int> u, vector<int> v) {
      |     ^~~~
highway.cpp:20:25: note:   no known conversion for argument 2 from 'std::vector<int>' to 'int'
   20 | int find(int start, int n, vector<int> u, vector<int> v) {
      |                     ~~~~^
In file included from /usr/include/c++/10/bits/locale_facets.h:48,
                 from /usr/include/c++/10/bits/basic_ios.h:37,
                 from /usr/include/c++/10/ios:44,
                 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 highway.cpp:2:
/usr/include/c++/10/bits/streambuf_iterator.h:422:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(std::istreambuf_iterator<_CharT>, std::istreambuf_iterator<_CharT>, const _CharT2&)'
  422 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/10/bits/streambuf_iterator.h:422:5: note:   template argument deduction/substitution failed:
highway.cpp:74:28: note:   mismatched types 'std::istreambuf_iterator<_CharT>' and 'int'
   74 |     int t = find(0, u, u, v);
      |                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from highway.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3894:5: note: candidate: 'template<class _IIter, class _Tp> _IIter std::find(_IIter, _IIter, const _Tp&)'
 3894 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
/usr/include/c++/10/bits/stl_algo.h:3894:5: note:   template argument deduction/substitution failed:
highway.cpp:74:28: note:   deduced conflicting types for parameter '_IIter' ('int' and 'std::vector<int>')
   74 |     int t = find(0, u, u, v);
      |                            ^
In file included from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from highway.cpp:2:
/usr/include/c++/10/pstl/glue_algorithm_defs.h:60:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::find(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
   60 | find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
/usr/include/c++/10/pstl/glue_algorithm_defs.h:60:1: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/pstl/glue_algorithm_defs.h:15,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from highway.cpp:2:
/usr/include/c++/10/pstl/execution_defs.h: In substitution of 'template<class _ExecPolicy, class _Tp> using __enable_if_execution_policy = typename std::enable_if<__pstl::execution::v1::is_execution_policy<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type>::value, _Tp>::type [with _ExecPolicy = int; _Tp = std::vector<int>]':
/usr/include/c++/10/pstl/glue_algorithm_defs.h:60:1:   required by substitution of 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::find(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&) [with _ExecutionPolicy = int; _ForwardIterator = std::vector<int>; _Tp = std::vector<int>]'
highway.cpp:74:28:   required from here
/usr/include/c++/10/pstl/execution_defs.h:150:7: error: no type named 'type' in 'struct std::enable_if<false, std::vector<int> >'
  150 | using __enable_if_execution_policy =
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
highway.cpp:74:9: warning: unused variable 't' [-Wunused-variable]
   74 |     int t = find(0, u, u, v);
      |         ^