답안 #679221

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
679221 2023-01-07T18:56:51 Z bebra Boat (APIO16_boat) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

#define dbg(x) cerr << #x << ": " << x << endl;


struct Seg {
    int l;
    int r;

    bool empty() const {
        return r - l + 1 <= 0;
    }

    bool operator<(const Seg& other) const {
        return tie(l, r) < tie(other.l, other.r);
    }

    bool operator==(const Seg& other) const {
        return tie(l, r) == tie(other.l, other.r);
    }

    friend Seg intersect(const Seg& lhs, const Seg& rhs) {
        return {max(lhs.l, rhs.l), min(lhs.r, rhs.r)};
    }
};


const int MOD = 1e9 + 7;
const int INV2 = 500000004;

int add(int a, int b) {
    int res = a + b;
    if (res >= MOD) res -= MOD;
    return res;
}

int mul(long long a, int b) {
    return a * b % MOD;
}

const int MAX_N = 500 + 1;
Seg segs[MAX_N];
vector<Seg> states[MAX_N];
vector<int> dp[MAX_N];
int main_idx[MAX_N];


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> segs[i].l >> segs[i].r;
        states[i].push_back(segs[i]);
    }
    segs[0] = {-1, -1};
    states[0].emplace_back(-1, -1);
    dp[0].assign(1, 1);
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        vector<int> ls;
        vector<int> rs;
        for (int j = 1; j <= n; ++j) {
            if (segs[j].l >= segs[i].l) {
                ls.push_back(segs[j].l);
            }
            if (segs[j].r <= segs[i].r) {
                rs.push_back(segs[j].r);
            }
        }
        sort(ls.begin(), ls.end());
        ls.resize(unique(ls.begin(), ls.end()) - ls.begin());
        sort(rs.begin(), rs.end());
        rs.resize(unique(rs.begin(), rs.end()) - rs.begin());
        for (auto l : ls) {
            for (auto r : rs) {
                if (l <= r) {
                    states[i].emplace_back(l, r);
                }
            }
        }
        for (auto l1 : ls) {
            for (auto l2 : ls) {
                if (l2 - 1 >= l1) {
                    states[i].emplace_back(l1, l2 - 1);
                }
            }
        }
        sort(states[i].begin(), states[i].end());
        states[i].resize(unique(states[i].begin(), states[i].end()) - states[i].begin());
        dp[i].resize(states[i].size());
        main_idx[i] = lower_bound(states[i].begin(), states[i].end(), segs[i]) - states[i].begin();

        int m = states[i].size();
        for (int j = 0; j < m; ++j) {
            auto [l1, r1] = states[i][j];
            for (int k = 0; k < i; ++k) {
                auto [l2, r2] = segs[k];
                if (r1 < l2) {
                    continue;
                }
                if (r2 < l1) {
                    dp[i][j] = add(dp[i][j], mul(dp[k][main_idx[k]], r1 - l1 + 1));
                    continue;
                }
                auto [l3, r3] = intersect(states[i][j], segs[k]);

                dp[i][j] = add(dp[i][j], mul(dp[k][main_idx[k]], r1 - r3));

                int idx1 = lower_bound(states[k].begin(), states[k].end(), Seg{l3, r3}) - states[k].begin();
                dp[i][j] = add(dp[i][j], mul(dp[k][idx1], mul(r3 - l3, INV2)));

                if (l3 - 1 >= l2) {
                    int idx2 = lower_bound(states[k].begin(), states[k].end(), Seg{l2, l3 - 1}) - states[k].begin();
                    dp[i][j] = add(dp[i][j], mul(r3 - l1 + 1, dp[k][idx2]));
                }
            }
        }
        ans = add(ans, dp[i][main_idx[i]]);
    }
    cout << ans << '\n';
    return 0;
}


/*
10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
*/

Compilation message

In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/c++allocator.h:33,
                 from /usr/include/c++/10/bits/allocator.h:46,
                 from /usr/include/c++/10/string:41,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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 boat.cpp:1:
/usr/include/c++/10/ext/new_allocator.h: In instantiation of 'void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = Seg; _Args = {int, int}; _Tp = Seg]':
/usr/include/c++/10/bits/alloc_traits.h:512:17:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(std::allocator_traits<std::allocator<_CharT> >::allocator_type&, _Up*, _Args&& ...) [with _Up = Seg; _Args = {int, int}; _Tp = Seg; std::allocator_traits<std::allocator<_CharT> >::allocator_type = std::allocator<Seg>]'
/usr/include/c++/10/bits/vector.tcc:115:30:   required from 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {int, int}; _Tp = Seg; _Alloc = std::allocator<Seg>; std::vector<_Tp, _Alloc>::reference = Seg&]'
boat.cpp:59:34:   required from here
/usr/include/c++/10/ext/new_allocator.h:150:4: error: new initializer expression list treated as compound expression [-fpermissive]
  150 |  { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/ext/new_allocator.h:150:4: error: no matching function for call to 'Seg::Seg(int)'
boat.cpp:7:8: note: candidate: 'Seg::Seg()'
    7 | struct Seg {
      |        ^~~
boat.cpp:7:8: note:   candidate expects 0 arguments, 1 provided
boat.cpp:7:8: note: candidate: 'constexpr Seg::Seg(const Seg&)'
boat.cpp:7:8: note:   no known conversion for argument 1 from 'int' to 'const Seg&'
boat.cpp:7:8: note: candidate: 'constexpr Seg::Seg(Seg&&)'
boat.cpp:7:8: note:   no known conversion for argument 1 from 'int' to 'Seg&&'
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/c++allocator.h:33,
                 from /usr/include/c++/10/bits/allocator.h:46,
                 from /usr/include/c++/10/string:41,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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 boat.cpp:1:
/usr/include/c++/10/ext/new_allocator.h: In instantiation of 'void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = Seg; _Args = {int&, int&}; _Tp = Seg]':
/usr/include/c++/10/bits/alloc_traits.h:512:17:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(std::allocator_traits<std::allocator<_CharT> >::allocator_type&, _Up*, _Args&& ...) [with _Up = Seg; _Args = {int&, int&}; _Tp = Seg; std::allocator_traits<std::allocator<_CharT> >::allocator_type = std::allocator<Seg>]'
/usr/include/c++/10/bits/vector.tcc:115:30:   required from 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {int&, int&}; _Tp = Seg; _Alloc = std::allocator<Seg>; std::vector<_Tp, _Alloc>::reference = Seg&]'
boat.cpp:80:48:   required from here
/usr/include/c++/10/ext/new_allocator.h:150:4: error: new initializer expression list treated as compound expression [-fpermissive]
  150 |  { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/ext/new_allocator.h:150:4: error: no matching function for call to 'Seg::Seg(int&)'
boat.cpp:7:8: note: candidate: 'Seg::Seg()'
    7 | struct Seg {
      |        ^~~
boat.cpp:7:8: note:   candidate expects 0 arguments, 1 provided
boat.cpp:7:8: note: candidate: 'constexpr Seg::Seg(const Seg&)'
boat.cpp:7:8: note:   no known conversion for argument 1 from 'int' to 'const Seg&'
boat.cpp:7:8: note: candidate: 'constexpr Seg::Seg(Seg&&)'
boat.cpp:7:8: note:   no known conversion for argument 1 from 'int' to 'Seg&&'
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/c++allocator.h:33,
                 from /usr/include/c++/10/bits/allocator.h:46,
                 from /usr/include/c++/10/string:41,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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 boat.cpp:1:
/usr/include/c++/10/ext/new_allocator.h: In instantiation of 'void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = Seg; _Args = {int&, int}; _Tp = Seg]':
/usr/include/c++/10/bits/alloc_traits.h:512:17:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(std::allocator_traits<std::allocator<_CharT> >::allocator_type&, _Up*, _Args&& ...) [with _Up = Seg; _Args = {int&, int}; _Tp = Seg; std::allocator_traits<std::allocator<_CharT> >::allocator_type = std::allocator<Seg>]'
/usr/include/c++/10/bits/vector.tcc:115:30:   required from 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {int&, int}; _Tp = Seg; _Alloc = std::allocator<Seg>; std::vector<_Tp, _Alloc>::reference = Seg&]'
boat.cpp:87:54:   required from here
/usr/include/c++/10/ext/new_allocator.h:150:4: error: new initializer expression list treated as compound expression [-fpermissive]
  150 |  { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/ext/new_allocator.h:150:4: error: no matching function for call to 'Seg::Seg(int)'
boat.cpp:7:8: note: candidate: 'Seg::Seg()'
    7 | struct Seg {
      |        ^~~
boat.cpp:7:8: note:   candidate expects 0 arguments, 1 provided
boat.cpp:7:8: note: candidate: 'constexpr Seg::Seg(const Seg&)'
boat.cpp:7:8: note:   no known conversion for argument 1 from 'int' to 'const Seg&'
boat.cpp:7:8: note: candidate: 'constexpr Seg::Seg(Seg&&)'
boat.cpp:7:8: note:   no known conversion for argument 1 from 'int' to 'Seg&&'