답안 #1031304

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1031304 2024-07-22T17:05:51 Z stdfloat Boat (APIO16_boat) C++17
9 / 100
1338 ms 1772 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define sz(v) (int)(v).size()

const int md = (int)1e9 + 7;

const int N = (int)1e5 + 1;

vector<int> fct(N), inv(N), inv_fct(N);

int pw(int x, int y) {
    int res = 1;
    while (y) {
        if (y & 1) res = (ll)res * x % md;

        x = (ll)x * x % md; y >>= 1;
    }

    return res;
}

int C(int n, int r) {
    int x = 1;
    for (int i = 1; i <= r; i++) x = (ll)x * (n - r + i) % md;

    return (ll)x * inv_fct[r] % md;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);

    fct[0] = inv[0] = inv_fct[0] = 1;
    for (int i = 1; i < N; i++) {
        inv[i] = pw(i, md - 2);
        fct[i] = (ll)fct[i - 1] * i % md;
        inv_fct[i] = pw(fct[i], md - 2);
    }

    int n;
    cin >> n;

    map<int, vector<int>> m;
    vector<int> a(n + 1), b(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];

        m[a[i]].push_back(i);
        m[b[i] + 1].push_back(-i);
    }

    vector<int> mv;
    for (auto i : m) mv.push_back(i.first);

    set<int> s;
    vector<int> dp(n + 1);
    for (int ii = 0; ii + 1 < sz(mv); ii++) {
        for (auto j : m[mv[ii]]) {
            if (0 < j) s.insert(j);
            else s.erase(-j); 
        }

        int R = mv[ii + 1] - mv[ii];
        vector<int> v(s.begin(), s.end()), nw_dp = dp;
        for (int i = 0; i < sz(v); i++) {
            int sm = 1;
            for (int j = 1; j < v[i]; j++) sm = (sm + dp[j]) % md;

            nw_dp[v[i]] = (dp[v[i]] + (ll)sm * R % md) % md;

            vector<int> p(n);
            for (int j = 0; j < n; j++) p[j] = ((j ? p[j - 1] : 0) + dp[j]) % md;

            for (int j = 1; j <= min(i, R - 1); j++) {
                int c = C(R, j + 1), x = fct[j - 1];
                // cout << "\nj " << j << ' ' << x << '\n';
                for (int k = i - j; k >= 0; k--) {
                    int pre = ((v[k] ? p[v[k] - 1] : 0) + 1) % md;
                    if (k != i - j) x = (ll)x * (i - k - 1) * inv[i - k - j] % md;

                    nw_dp[v[i]] = (nw_dp[v[i]] + ((ll)pre * ((ll)x * inv_fct[j - 1] % md) % md) * c % md) % md;

                    // cout << i - k - 1 << ' ' << j - 1 << ' ' << x << ' ' << (ll)x * inv_fct[j - 1] % md << ' ' << C(i - k - 1, j - 1) << '\n';
                }
            }
        }

        dp = nw_dp;
    }

    int sm = 0;
    for (auto i : dp) sm = (sm + i) % md;

    cout << sm << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1624 KB Output is correct
2 Correct 34 ms 1632 KB Output is correct
3 Correct 33 ms 1764 KB Output is correct
4 Correct 34 ms 1632 KB Output is correct
5 Correct 32 ms 1628 KB Output is correct
6 Correct 32 ms 1628 KB Output is correct
7 Correct 32 ms 1640 KB Output is correct
8 Correct 34 ms 1628 KB Output is correct
9 Correct 32 ms 1628 KB Output is correct
10 Correct 31 ms 1640 KB Output is correct
11 Correct 32 ms 1644 KB Output is correct
12 Correct 32 ms 1628 KB Output is correct
13 Correct 31 ms 1636 KB Output is correct
14 Correct 34 ms 1632 KB Output is correct
15 Correct 32 ms 1632 KB Output is correct
16 Correct 34 ms 1640 KB Output is correct
17 Correct 32 ms 1628 KB Output is correct
18 Correct 31 ms 1636 KB Output is correct
19 Correct 31 ms 1636 KB Output is correct
20 Correct 31 ms 1632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1624 KB Output is correct
2 Correct 34 ms 1632 KB Output is correct
3 Correct 33 ms 1764 KB Output is correct
4 Correct 34 ms 1632 KB Output is correct
5 Correct 32 ms 1628 KB Output is correct
6 Correct 32 ms 1628 KB Output is correct
7 Correct 32 ms 1640 KB Output is correct
8 Correct 34 ms 1628 KB Output is correct
9 Correct 32 ms 1628 KB Output is correct
10 Correct 31 ms 1640 KB Output is correct
11 Correct 32 ms 1644 KB Output is correct
12 Correct 32 ms 1628 KB Output is correct
13 Correct 31 ms 1636 KB Output is correct
14 Correct 34 ms 1632 KB Output is correct
15 Correct 32 ms 1632 KB Output is correct
16 Correct 34 ms 1640 KB Output is correct
17 Correct 32 ms 1628 KB Output is correct
18 Correct 31 ms 1636 KB Output is correct
19 Correct 31 ms 1636 KB Output is correct
20 Correct 31 ms 1632 KB Output is correct
21 Incorrect 1338 ms 1772 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 78 ms 1628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1624 KB Output is correct
2 Correct 34 ms 1632 KB Output is correct
3 Correct 33 ms 1764 KB Output is correct
4 Correct 34 ms 1632 KB Output is correct
5 Correct 32 ms 1628 KB Output is correct
6 Correct 32 ms 1628 KB Output is correct
7 Correct 32 ms 1640 KB Output is correct
8 Correct 34 ms 1628 KB Output is correct
9 Correct 32 ms 1628 KB Output is correct
10 Correct 31 ms 1640 KB Output is correct
11 Correct 32 ms 1644 KB Output is correct
12 Correct 32 ms 1628 KB Output is correct
13 Correct 31 ms 1636 KB Output is correct
14 Correct 34 ms 1632 KB Output is correct
15 Correct 32 ms 1632 KB Output is correct
16 Correct 34 ms 1640 KB Output is correct
17 Correct 32 ms 1628 KB Output is correct
18 Correct 31 ms 1636 KB Output is correct
19 Correct 31 ms 1636 KB Output is correct
20 Correct 31 ms 1632 KB Output is correct
21 Incorrect 1338 ms 1772 KB Output isn't correct
22 Halted 0 ms 0 KB -