제출 #662904

#제출 시각아이디문제언어결과실행 시간메모리
662904Trisanu_DasRoller Coaster Railroad (IOI16_railroad)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long vector<int> nxt; int parent(int u) { return nxt[u] != -1 ? nxt[u] = parent(nxt[u]) : u; } bool unite(int u, int v) { u = parent(u); v = parent(v); if (u == v) return false; nxt[v] = u; return true; } ll plan_roller_coaster(vector<int> s, vector<int> t) { s.push_back(inf); t.push_back(1); int n = s.size(); vector<int> p = s; p.insert(p.end(), t.begin(), t.end()); sort(p.begin()); p.erase(unique(p.begin(), p.end()), p.end()); int m = p.size(); nxt.resize(m, -1); vector<int> b(m--); for(int i = 0; i < n; i++) { int l = lower_bound(p.begin(), p.end(), s[i]) - p.begin(), r = lower_bound(p.begin(), p.end(), t[i]) - p.begin(); unite(l, r); ++b[l]; --b[r]; } for(int i = 0; i < m; i++) b[i + 1] += b[i]; vector<pair<int, int>> e; ll ans = 0; for(int i = 0; i < m; i++) { ll d = p[i + 1] - p[i]; if (b[i]) { unite(i, i + 1); if (b[i] > 0) ans += b[i] * d; } else e.push_back(d, i); } sort(e.begin(), e.end()); for (auto u : e) if (unite(u.second, u.second + 1)) ans += u.first; return ans; }

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

railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:14:14: error: 'inf' was not declared in this scope; did you mean 'ynf'?
   14 |  s.push_back(inf); t.push_back(1); int n = s.size();
      |              ^~~
      |              ynf
railroad.cpp:16:16: error: no matching function for call to 'sort(std::vector<int>::iterator)'
   16 |  sort(p.begin()); p.erase(unique(p.begin(), p.end()), p.end());
      |                ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from railroad.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:4849:5: note: candidate: 'template<class _RAIter> void std::sort(_RAIter, _RAIter)'
 4849 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |     ^~~~
/usr/include/c++/10/bits/stl_algo.h:4849:5: note:   template argument deduction/substitution failed:
railroad.cpp:16:16: note:   candidate expects 2 arguments, 1 provided
   16 |  sort(p.begin()); p.erase(unique(p.begin(), p.end()), p.end());
      |                ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from railroad.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:4880:5: note: candidate: 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)'
 4880 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~
/usr/include/c++/10/bits/stl_algo.h:4880:5: note:   template argument deduction/substitution failed:
railroad.cpp:16:16: note:   candidate expects 3 arguments, 1 provided
   16 |  sort(p.begin()); p.erase(unique(p.begin(), p.end()), p.end());
      |                ^
In file included from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from railroad.cpp:1:
/usr/include/c++/10/pstl/glue_algorithm_defs.h:292:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator, class _Compare> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Compare)'
  292 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp);
      | ^~~~
/usr/include/c++/10/pstl/glue_algorithm_defs.h:292:1: note:   template argument deduction/substitution failed:
railroad.cpp:16:16: note:   candidate expects 4 arguments, 1 provided
   16 |  sort(p.begin()); p.erase(unique(p.begin(), p.end()), p.end());
      |                ^
In file included from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from railroad.cpp:1:
/usr/include/c++/10/pstl/glue_algorithm_defs.h:296:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator)'
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
/usr/include/c++/10/pstl/glue_algorithm_defs.h:296:1: note:   template argument deduction/substitution failed:
railroad.cpp:16:16: note:   candidate expects 3 arguments, 1 provided
   16 |  sort(p.begin()); p.erase(unique(p.begin(), p.end()), p.end());
      |                ^
railroad.cpp:30:26: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(long long int&, int&)'
   30 |   } else e.push_back(d, i);
      |                          ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from railroad.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note:   candidate expects 1 argument, 2 provided