제출 #218262

#제출 시각아이디문제언어결과실행 시간메모리
218262emil_physmathAliens (IOI16_aliens)C++17
컴파일 에러
0 ms0 KiB
#include "aliens.h"
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using llong = long long;
struct Rat
{
    llong a, b;
    Rat(llong a_ = 0, llong b_ = 1)
        : a(a_)
        , b(b_)
    {}
    Rat operator-() const { return Rat(-a, b); }
};
const Rat inf = Rat(1000'000'000LL, 1);
bool operator<(const Rat& l, const Rat& r)
{
    if ((l.b < 0) ^ (r.b < 0))
        return l.a * r.b > r.a * l.b;
    return l.a * r.b < r.a * l.b;
}
struct Line
{
    llong k, b;
    Line(llong k_ = 1, llong b_ = 0)
        : k(k_)
        , b(b_)
    {}
    llong operator()(llong x) const { return k * x + b; }
};
Rat Inter(const Line& a, const Line& b) { return Rat(a.b - b.b, b.k - a.k); }

vector<vector<Line> > cht;
vector<vector<Rat> > st;
void Add(vector<Line>& cht, vector<Rat>& st, Line l, llong ind)
{
    while (cht.size() >= 2 && Inter(cht.back(), l) < Inter(*next(cht.rbegin()), l))
    {
        cht.pop_back();
        st.pop_back();
    }
    if (cht.size())
        st.push_back(Inter(cht.back(), l));
    else
        st.push_back(-inf);
    cht.push_back(l);
}
llong Min(vector<Line>& cht, vector<Rat>& st, llong x)
{
    if (cht.size() == 2 && cht[1].k == -2 && cht[1].b == 2 && x == 3)
        cerr << "";
    llong i = prev(upper_bound(st.begin(), st.end(), Rat(x))) - st.begin();
    return cht[i](x);
}
long long take_photos(llong n, llong m, llong k, std::vector<llong> r, std::vector<llong> c) {
    swap(m, n);
    cht.resize(k + 1); st.resize(k + 1);
    struct Pollong { llong x, y; };
    vector<Pollong> a(m);
    for (llong i = 0; i < m; ++i)
    {
        if (r[i] < c[i])
            swap(r[i], c[i]);
        a[i] = Pollong{r[i], n - c[i] - 1};
    }
    sort(a.begin(), a.end(), [](const Pollong& l, const Pollong& r) {
         return make_pair(l.x, l.y) < make_pair(r.x, r.y);
    });
    vector<Pollong> b;
    for (llong i = 0; i < a.size(); ++i)
    {
        while (b.size() && b.back().y <= a[i].y)
            b.pop_back();
        b.push_back(a[i]);
    }
    vector<llong> hei(b.size());
    for (llong i = 0; i < b.size(); ++i)
        hei[i] = b[i].y + b[i].x - n + 2;
    vector<vector<llong> > dp(b.size(), vector<llong>(k + 1));
    for (llong j = 1; j <= k; ++j)
    {
        dp[0][j] = hei[0] * hei[0];
        llong i = 0;
        llong l = b[0].x;
        Add(cht[j], st[j], Line(2LL * hei[i] - 2LL * l, -2LL * l * hei[i] + l * l + dp[i][j]), 0);
    }
    for (llong i = 1; i < b.size(); ++i)
        for (llong j = 1; j <= k; ++j)
        {
            dp[i][j] = b[i].x * b[i].x + Min(cht[j], st[j], b[i].x);
            if (j > 1)
            {
                llong curdp = dp[i - 1][j - 1] + hei[i] * hei[i] - max(b[i - 1].x - b[i].x + hei[i], 0) * max(b[i - 1].x - b[i].x + hei[i], 0);
                llong l = b[i].x;
                Add(cht[j], st[j], Line(2LL * hei[i] - 2LL * l, -2LL * l * hei[i] + l * l + curdp), i);
                if (curdp < dp[i][j])
                    dp[i][j] = curdp;
            }
        }
    llong ans = dp[b.size() - 1][1];
    for (llong j = 2; j <= k; ++j)
        ans = min(ans, dp[b.size() - 1][j]);
    return ans;
}

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

aliens.cpp: In function 'long long int take_photos(llong, llong, llong, std::vector<long long int>, std::vector<long long int>)':
aliens.cpp:71:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (llong i = 0; i < a.size(); ++i)
                       ~~^~~~~~~~~~
aliens.cpp:78:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (llong i = 0; i < b.size(); ++i)
                       ~~^~~~~~~~~~
aliens.cpp:88:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (llong i = 1; i < b.size(); ++i)
                       ~~^~~~~~~~~~
aliens.cpp:94:103: error: no matching function for call to 'max(llong, int)'
                 llong curdp = dp[i - 1][j - 1] + hei[i] * hei[i] - max(b[i - 1].x - b[i].x + hei[i], 0) * max(b[i - 1].x - b[i].x + hei[i], 0);
                                                                                                       ^
In file included from /usr/include/c++/7/vector:60:0,
                 from aliens.h:3,
                 from aliens.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
aliens.cpp:94:103: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
                 llong curdp = dp[i - 1][j - 1] + hei[i] * hei[i] - max(b[i - 1].x - b[i].x + hei[i], 0) * max(b[i - 1].x - b[i].x + hei[i], 0);
                                                                                                       ^
In file included from /usr/include/c++/7/vector:60:0,
                 from aliens.h:3,
                 from aliens.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
aliens.cpp:94:103: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
                 llong curdp = dp[i - 1][j - 1] + hei[i] * hei[i] - max(b[i - 1].x - b[i].x + hei[i], 0) * max(b[i - 1].x - b[i].x + hei[i], 0);
                                                                                                       ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from aliens.cpp:2:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
aliens.cpp:94:103: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
                 llong curdp = dp[i - 1][j - 1] + hei[i] * hei[i] - max(b[i - 1].x - b[i].x + hei[i], 0) * max(b[i - 1].x - b[i].x + hei[i], 0);
                                                                                                       ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from aliens.cpp:2:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
aliens.cpp:94:103: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
                 llong curdp = dp[i - 1][j - 1] + hei[i] * hei[i] - max(b[i - 1].x - b[i].x + hei[i], 0) * max(b[i - 1].x - b[i].x + hei[i], 0);
                                                                                                       ^
aliens.cpp:94:142: error: no matching function for call to 'max(llong, int)'
                 llong curdp = dp[i - 1][j - 1] + hei[i] * hei[i] - max(b[i - 1].x - b[i].x + hei[i], 0) * max(b[i - 1].x - b[i].x + hei[i], 0);
                                                                                                                                              ^
In file included from /usr/include/c++/7/vector:60:0,
                 from aliens.h:3,
                 from aliens.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
aliens.cpp:94:142: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
                 llong curdp = dp[i - 1][j - 1] + hei[i] * hei[i] - max(b[i - 1].x - b[i].x + hei[i], 0) * max(b[i - 1].x - b[i].x + hei[i], 0);
                                                                                                                                              ^
In file included from /usr/include/c++/7/vector:60:0,
                 from aliens.h:3,
                 from aliens.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
aliens.cpp:94:142: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
                 llong curdp = dp[i - 1][j - 1] + hei[i] * hei[i] - max(b[i - 1].x - b[i].x + hei[i], 0) * max(b[i - 1].x - b[i].x + hei[i], 0);
                                                                                                                                              ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from aliens.cpp:2:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
aliens.cpp:94:142: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
                 llong curdp = dp[i - 1][j - 1] + hei[i] * hei[i] - max(b[i - 1].x - b[i].x + hei[i], 0) * max(b[i - 1].x - b[i].x + hei[i], 0);
                                                                                                                                              ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from aliens.cpp:2:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
aliens.cpp:94:142: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
                 llong curdp = dp[i - 1][j - 1] + hei[i] * hei[i] - max(b[i - 1].x - b[i].x + hei[i], 0) * max(b[i - 1].x - b[i].x + hei[i], 0);
                                                                                                                                              ^