Submission #700982

#TimeUsernameProblemLanguageResultExecution timeMemory
700982rembocoderAliens (IOI16_aliens)C++17
Compilation error
0 ms0 KiB
#include "aliens.h"

#include<bits/stdc++.h>

using namespace std;

#define int int64_t

bool cmp(const pair<int, int>& a, const pair<int, int>& b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }
    return a.second > b.second;
}

int divide_up(int a, int b) {
    if (b < 0) {
        a = -a;
        b = -b;
    }
    if (a >= 0) {
        return (a + b - 1) / b;
    }
    return a / b;
}

long long take_photos(int32_t n, int32_t m, int32_t k, vector<int32_t> points_x, vector<int32_t> points_y) {
    vector<pair<int, int>> segs(n);
    for (int i = 0; i < n; i++) {
        segs[i] = {min(points_x[i], points_y[i]), max(points_x[i], points_y[i])};
    }
    sort(segs.begin(), segs.end(), cmp);
    vector<pair<int, int>> new_segs;
    new_segs.push_back({-1, -1});
    int largest_r = -2e18;
    for (auto [l, r]: segs) {
        if (r <= largest_r) {
            continue;
        }
        largest_r = r;
        new_segs.push_back({l, r});
    }
    segs = new_segs;
    n = segs.size();
    new_segs.clear();

    vector<vector<int>> a(k + 1, vector<int>(n));
    vector<int> b(n);
    for (int i = 0; i < n - 1; i++) {
        b[i] = -2 * segs[i + 1].first;
    }

    vector<vector<int>> dp(k + 1, vector<int>(n, 2e18));

    auto count_a = [&](int j, int i) {
        if (i == n - 1) {
            return;
        }
        a[j][i] = dp[j][i] + (segs[i + 1].first - 1) * (segs[i + 1].first - 1)
                - max(0ll, segs[i].second - segs[i + 1].first + 1) *
                  max(0ll, segs[i].second - segs[i + 1].first + 1);
    };

    vector<vector<pair<int, int>>> ch(k + 1);
    vector<int> last(k + 1);
    dp[0][0] = 0;
    count_a(0, 0);
    ch[0].push_back({-1, 0});
    for (int i = 1; i < n; i++) {
        for (int j = 1; j <= i && j <= k; j++) {
            // dp[j][i]
            int x = segs[i].second;
            while (last[j - 1] + 1 < ch[j - 1].size() && ch[j - 1][last[j - 1] + 1].first <= x) {
                last[j - 1]++;
            }
            int from = ch[j - 1][last[j - 1]].second;
            dp[j][i] = segs[i].second * segs[i].second + 2 * segs[i].second + a[j - 1][from] + b[from] * x;
            //cerr << x << ' ' << from << endl;
            //cerr << segs[i].second * segs[i].second - 2 * segs[i].second << ' ' << a[j - 1][from] << ' ' << << endl;
            count_a(j, i);
            if (i == n - 1) {
                continue;
            }
            if (ch[j].empty()) {
                ch[j].push_back({-1, i});
                continue;
            }
            while (true) {
                x = ch[j].back().first;
                int ind = ch[j].back().second;
                if (a[j][ind] + b[ind] * x < a[j][i] + b[i] * x) {
                    break;
                }
                ch[j].pop_back();
            }
            int ind = ch[j].back().second;
            x = divide_up(a[j][i] - a[j][ind], b[ind] - b[i]);
            ch[j].push_back({x, i});
            last[j] = min(last[j], int(ch[j].size() - 1));
        }
    }
    int ans = 2e18;
    for (int j = 1; j <= k; j++) {
        ans = min(ans, dp[j][n - 1]);
    }
    return ans;
}

Compilation message (stderr)

aliens.cpp: In lambda function:
aliens.cpp:60:66: error: no matching function for call to 'max(long long int, long int)'
   60 |                 - max(0ll, segs[i].second - segs[i + 1].first + 1) *
      |                                                                  ^
In file included from /usr/include/c++/10/vector:60,
                 from aliens.h:3,
                 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:60:66: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int')
   60 |                 - max(0ll, segs[i].second - segs[i + 1].first + 1) *
      |                                                                  ^
In file included from /usr/include/c++/10/vector:60,
                 from aliens.h:3,
                 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:60:66: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int')
   60 |                 - max(0ll, segs[i].second - segs[i + 1].first + 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:3:
/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:60:66: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   60 |                 - max(0ll, segs[i].second - segs[i + 1].first + 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:3:
/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:60:66: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   60 |                 - max(0ll, segs[i].second - segs[i + 1].first + 1) *
      |                                                                  ^
aliens.cpp:61:66: error: no matching function for call to 'max(long long int, long int)'
   61 |                   max(0ll, segs[i].second - segs[i + 1].first + 1);
      |                                                                  ^
In file included from /usr/include/c++/10/vector:60,
                 from aliens.h:3,
                 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:61:66: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int')
   61 |                   max(0ll, segs[i].second - segs[i + 1].first + 1);
      |                                                                  ^
In file included from /usr/include/c++/10/vector:60,
                 from aliens.h:3,
                 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:61:66: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int')
   61 |                   max(0ll, segs[i].second - segs[i + 1].first + 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:3:
/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:61:66: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   61 |                   max(0ll, segs[i].second - segs[i + 1].first + 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:3:
/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:61:66: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   61 |                   max(0ll, segs[i].second - segs[i + 1].first + 1);
      |                                                                  ^
aliens.cpp: In function 'long long int take_photos(int32_t, int32_t, int32_t, std::vector<int>, std::vector<int>)':
aliens.cpp:73:36: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'} and 'std::vector<std::pair<long int, long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |             while (last[j - 1] + 1 < ch[j - 1].size() && ch[j - 1][last[j - 1] + 1].first <= x) {