제출 #986620

#제출 시각아이디문제언어결과실행 시간메모리
986620tfgsAliens (IOI16_aliens)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #include "aliens.h" using namespace std; #define int int64_t const int inf = 2e18; #ifdef LOCAL #include "algo/debug.h" #endif #define f first #define s second template<class T> using V = vector<T>; using vi = V<int>; using vb = V<bool>; using vs = V<string>; #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define pb push_back #define lb lower_bound #define ub upper_bound template<class T> int lwb(V<T>& a, const T& b) { return lb(all(a),b)-begin(a); } template<class T> int upb(V<T>& a, const T& b) { return ub(all(a),b)-begin(a); } template<class T> bool ckmin(T& a, const T& b) { return a > b ? a=b, true : false; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a=b, true : false; } using pt = complex<int>; #define x real() #define y imag() template<class T> istream& operator>>(istream& in, complex<T>& o) { T X, Y; in >> X >> Y; o.real(X); o.imag(Y); return in; } template<class T> bool operator<(const complex<T>& a, const complex<T>& b) { if (a.x == b.x) return a.y > b.y; return a.x < b.x; } template<class T> T sqr(const T& a) { return a*a; } int cdiv(int a, int b) {return a/b + ((a^b)>0&&a%b);} int n, m, k; V<pt> inp, pts; // void solve() { // cin >> n >> m >> k; int take_photos(int N, int M, int K, vi XS, vi YS) { n = N; m = M; k = K; inp.resize(n); for (int i = 0; i < n; i++) { // cin >> inp[i]; inp[i] = {XS[i], YS[i]}; if (inp[i].x > inp[i].y) inp[i] = {inp[i].y, inp[i].x}; } inp.pb({-1, -1}); n++; sort(all(inp), [&](const pt& a, const pt& b) {return a < b;}); int max_y = -2; for (int i = 0; i < n; i++) { if (!ckmax(max_y, inp[i].y)) continue; pts.pb(inp[i]); } n = pts.size(); k = min(n-1, k); vi l(n), r(n); for (int i = 0; i < n; i++) l[i] = pts[i].x, r[i] = pts[i].y+1; vi dp(n, inf); dp[0] = 0; for (int p = 0; p < k; p++) { vi a(n-1), b(n-1); for (int i = 0; i < n-1; i++) { a[i] = dp[i] + sqr(l[i+1]) - sqr(max(0ll, r[i]-l[i+1])); b[i] = 2*l[i+1]; } V<pt> ch = { {0, p} }; vi new_dp(n, inf); int cur_entry = 0; for (int i = p+1; i < n; i++) { while (cur_entry+1 < ch.size() && ch[cur_entry+1].x <= r[i]) { cur_entry++; } int j = ch[cur_entry].y; new_dp[i] = sqr(r[i]) + a[j] - b[j]*r[i]; if (i == n-1 || p == 0) { continue; } while (!ch.empty()) { int j = ch.back().y; int X = ch.back().x; if (a[i]-b[i]*X <= a[j]-b[j]*X) { ch.pop_back(); } else { break; } } if (ch.empty()) { ch.pb({0ll, i}); } else { int j = ch.back().y; int X = cdiv(a[i]-a[j], b[i]-b[j]); ch.pb({X, i}); } if (cur_entry >= ch.size()) { cur_entry = ch.size()-1; } } dp = new_dp; } cout << dp.back() << '\n'; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); return 0; }

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

aliens.cpp: In function 'int64_t take_photos(int64_t, int64_t, int64_t, vi, vi)':
aliens.cpp:72:66: error: no matching function for call to 'max(long long int, __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type)'
   72 |             a[i] = dp[i] + sqr(l[i+1]) - sqr(max(0ll, r[i]-l[i+1]));
      |                                                                  ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from aliens.cpp:1:
/usr/include/c++/10/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++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
aliens.cpp:72:66: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'})
   72 |             a[i] = dp[i] + sqr(l[i+1]) - sqr(max(0ll, r[i]-l[i+1]));
      |                                                                  ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from aliens.cpp:1:
/usr/include/c++/10/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++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
aliens.cpp:72:66: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'})
   72 |             a[i] = dp[i] + sqr(l[i+1]) - sqr(max(0ll, r[i]-l[i+1]));
      |                                                                  ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from aliens.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
aliens.cpp:72:66: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   72 |             a[i] = dp[i] + sqr(l[i+1]) - sqr(max(0ll, r[i]-l[i+1]));
      |                                                                  ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from aliens.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
aliens.cpp:72:66: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   72 |             a[i] = dp[i] + sqr(l[i+1]) - sqr(max(0ll, r[i]-l[i+1]));
      |                                                                  ^
aliens.cpp:79:32: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<std::complex<long int>, std::allocator<std::complex<long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |             while (cur_entry+1 < ch.size() && ch[cur_entry+1].x <= r[i]) {
      |                    ~~~~~~~~~~~~^~~~~~~~~~~
aliens.cpp:103:27: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<std::complex<long int>, std::allocator<std::complex<long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |             if (cur_entry >= ch.size()) {
      |                 ~~~~~~~~~~^~~~~~~~~~~~
aliens.cpp:110:1: warning: no return statement in function returning non-void [-Wreturn-type]
  110 | }
      | ^
aliens.cpp: In function 'int main()':
aliens.cpp:115:5: error: 'solve' was not declared in this scope
  115 |     solve();
      |     ^~~~~