Submission #1031141

# Submission time Handle Problem Language Result Execution time Memory
1031141 2024-07-22T15:26:41 Z stdfloat Boat (APIO16_boat) C++17
9 / 100
2000 ms 592 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

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

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, y = 1;
    for (int i = 1; i <= r; i++) {
        x = (ll)x * (n - r + i) % md;
        y = (ll)y * i % md;
    }

    return (ll)x * pw(y, md - 2) % md;
}

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

    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 < (int)mv.size(); 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 < (int)v.size(); 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;

            for (int j = 1; j <= min(i, R - 1); j++) {
                int c = C(R, j + 1), sm = 1;
                for (int k = 1; k <= v[i - j]; k++) sm = (sm + dp[k]) % md;
                for (int k = i - j; k >= 0; k--) {
                    int sm = 1;
                    for (int l = 1; l < v[k]; l++) sm = (sm + dp[l]) % md;
                
                    nw_dp[v[i]] = (nw_dp[v[i]] + ((ll)sm * C(i - k - 1, j - 1) % md) * c % md) % md;
                }
            }
        }

        dp = nw_dp;
    }

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

    cout << sm << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Execution timed out 2056 ms 556 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 563 ms 592 KB Output is correct
2 Correct 318 ms 344 KB Output is correct
3 Correct 491 ms 456 KB Output is correct
4 Correct 570 ms 464 KB Output is correct
5 Correct 701 ms 344 KB Output is correct
6 Execution timed out 2025 ms 344 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Execution timed out 2056 ms 556 KB Time limit exceeded
22 Halted 0 ms 0 KB -