답안 #499783

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
499783 2021-12-29T12:36:18 Z Stickfish Boat (APIO16_boat) C++17
9 / 100
828 ms 12236 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

const ll MOD = 1000000007;
const int MAXN = 502;

ll fact[MAXN * 2];
ll rfact[MAXN * 2];

ll pw(ll a, ll m) {
    if (!m)
        return 1;
    a %= MOD;
    if (m % 2)
        return (a * pw(a, m - 1)) % MOD;
    return pw(a * a, m / 2);
}

ll choose[MAXN * 2][MAXN];

ll dp[MAXN * 2][MAXN];
ll ndp[MAXN * 2][MAXN];

ll a[MAXN];
ll b[MAXN];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    rfact[0] = fact[0] = 1;
    for (int i = 1; i < 2 * MAXN; ++i) {
        fact[i] = (fact[i - 1] * i) % MOD;
        rfact[i] = pw(fact[i], MOD - 2);
    }
    int n;
    cin >> n;
    vector<ll> cpr = {0};
    vector<ll> sz;
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        ++b[i];
        cpr.push_back(a[i]);
        cpr.push_back(b[i]);
    }
    sort(cpr.begin(), cpr.end());
    cpr.resize(unique(cpr.begin(), cpr.end()) - cpr.begin());
    int m = cpr.size();
    for (int i = 0; i + 1 < m; ++i) {
        sz.push_back(cpr[i + 1] - cpr[i]);
        choose[i][0] = 1;
        for (ll k = 1; k <= i && k <= sz[i]; ++k) {
            choose[i][k] = (choose[i][k - 1] * (sz[i] - k + 1)) % MOD;
            choose[i][k] = (choose[i][k] * pw(k, MOD - 2)) % MOD;
        }
    }
    //printf("\n");
    for (int i = 0; i < n; ++i) {
        a[i] = lower_bound(cpr.begin(), cpr.end(), a[i]) - cpr.begin();
        b[i] = lower_bound(cpr.begin(), cpr.end(), b[i]) - cpr.begin(); } for (int i = 0; i < m; ++i)
        dp[i][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            for (int k = 0; k <= n; ++k)
                ndp[j][k] = 0;
        }
        for (int j = b[i] - 1; j >= a[i]; --j) {
            for (ll k = 0; k <= sz[j] && k <= i + 1; ++k) {
                if (k)
                    ndp[j][k] += dp[j][k - 1];
                ndp[j][k] %= MOD;
                ndp[j + 1][0] += ndp[j][k] * choose[j][k];
                ndp[j + 1][0] %= MOD;
            }
        }
        for (int j = 1; j < m; ++j) {
            ndp[j][0] += ndp[j - 1][0];
            ndp[j][0] %= MOD;
        }
        for (int j = 0; j < m; ++j) {
            for (int k = 0; k <= n; ++k) {
                ndp[j][k] += dp[j][k];
                ndp[j][k] %= MOD;
            }
        }
        for (int j = 0; j < m; ++j) {
            for (int k = 0; k <= n; ++k)
                dp[j][k] = ndp[j][k];
        }
        //printf("---\n");
        //for (int j = 0; j < m; ++j) {
            //for (int k = 0; k <= n; ++k)
                //printf("%Ld ", dp[j][k]);
            //printf("\n");
        //}
    }
    cout << dp[m - 1][0] - 1 << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 804 ms 12144 KB Output is correct
2 Correct 795 ms 12164 KB Output is correct
3 Correct 771 ms 12152 KB Output is correct
4 Correct 754 ms 12144 KB Output is correct
5 Correct 744 ms 12228 KB Output is correct
6 Correct 815 ms 12152 KB Output is correct
7 Correct 733 ms 12144 KB Output is correct
8 Correct 771 ms 12148 KB Output is correct
9 Correct 741 ms 12144 KB Output is correct
10 Correct 828 ms 12208 KB Output is correct
11 Correct 755 ms 12216 KB Output is correct
12 Correct 769 ms 12072 KB Output is correct
13 Correct 780 ms 12236 KB Output is correct
14 Correct 750 ms 12148 KB Output is correct
15 Correct 742 ms 12148 KB Output is correct
16 Correct 95 ms 2444 KB Output is correct
17 Correct 101 ms 2508 KB Output is correct
18 Correct 98 ms 2512 KB Output is correct
19 Correct 109 ms 2508 KB Output is correct
20 Correct 110 ms 2532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 804 ms 12144 KB Output is correct
2 Correct 795 ms 12164 KB Output is correct
3 Correct 771 ms 12152 KB Output is correct
4 Correct 754 ms 12144 KB Output is correct
5 Correct 744 ms 12228 KB Output is correct
6 Correct 815 ms 12152 KB Output is correct
7 Correct 733 ms 12144 KB Output is correct
8 Correct 771 ms 12148 KB Output is correct
9 Correct 741 ms 12144 KB Output is correct
10 Correct 828 ms 12208 KB Output is correct
11 Correct 755 ms 12216 KB Output is correct
12 Correct 769 ms 12072 KB Output is correct
13 Correct 780 ms 12236 KB Output is correct
14 Correct 750 ms 12148 KB Output is correct
15 Correct 742 ms 12148 KB Output is correct
16 Correct 95 ms 2444 KB Output is correct
17 Correct 101 ms 2508 KB Output is correct
18 Correct 98 ms 2512 KB Output is correct
19 Correct 109 ms 2508 KB Output is correct
20 Correct 110 ms 2532 KB Output is correct
21 Incorrect 601 ms 11128 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 2728 KB Output is correct
2 Correct 15 ms 2636 KB Output is correct
3 Correct 12 ms 2708 KB Output is correct
4 Correct 12 ms 2636 KB Output is correct
5 Correct 13 ms 2636 KB Output is correct
6 Correct 14 ms 2728 KB Output is correct
7 Correct 14 ms 2636 KB Output is correct
8 Correct 14 ms 2724 KB Output is correct
9 Correct 14 ms 2728 KB Output is correct
10 Correct 13 ms 2724 KB Output is correct
11 Correct 13 ms 2636 KB Output is correct
12 Correct 13 ms 2728 KB Output is correct
13 Correct 12 ms 2732 KB Output is correct
14 Correct 12 ms 2728 KB Output is correct
15 Correct 13 ms 2724 KB Output is correct
16 Incorrect 6 ms 1612 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 804 ms 12144 KB Output is correct
2 Correct 795 ms 12164 KB Output is correct
3 Correct 771 ms 12152 KB Output is correct
4 Correct 754 ms 12144 KB Output is correct
5 Correct 744 ms 12228 KB Output is correct
6 Correct 815 ms 12152 KB Output is correct
7 Correct 733 ms 12144 KB Output is correct
8 Correct 771 ms 12148 KB Output is correct
9 Correct 741 ms 12144 KB Output is correct
10 Correct 828 ms 12208 KB Output is correct
11 Correct 755 ms 12216 KB Output is correct
12 Correct 769 ms 12072 KB Output is correct
13 Correct 780 ms 12236 KB Output is correct
14 Correct 750 ms 12148 KB Output is correct
15 Correct 742 ms 12148 KB Output is correct
16 Correct 95 ms 2444 KB Output is correct
17 Correct 101 ms 2508 KB Output is correct
18 Correct 98 ms 2512 KB Output is correct
19 Correct 109 ms 2508 KB Output is correct
20 Correct 110 ms 2532 KB Output is correct
21 Incorrect 601 ms 11128 KB Output isn't correct
22 Halted 0 ms 0 KB -