Submission #499777

# Submission time Handle Problem Language Result Execution time Memory
499777 2021-12-29T12:26:18 Z Stickfish Boat (APIO16_boat) C++17
9 / 100
1737 ms 12380 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]);
        for (int k = 0; k <= i; ++k) {
            choose[i][k] = 1;
            for (int t = sz[i]; t > sz[i] - k; --t) {
                choose[i][k] = (choose[i][k] * t) % MOD;
            }
            choose[i][k] = (choose[i][k] * rfact[k]) % 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 (int k = 0; k <= n; ++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;
}
# Verdict Execution time Memory Grader output
1 Correct 1430 ms 12316 KB Output is correct
2 Correct 1414 ms 12208 KB Output is correct
3 Correct 1434 ms 12188 KB Output is correct
4 Correct 1479 ms 12236 KB Output is correct
5 Correct 1448 ms 12060 KB Output is correct
6 Correct 1462 ms 12208 KB Output is correct
7 Correct 1471 ms 12152 KB Output is correct
8 Correct 1484 ms 12152 KB Output is correct
9 Correct 1447 ms 12240 KB Output is correct
10 Correct 1466 ms 12192 KB Output is correct
11 Correct 1457 ms 12380 KB Output is correct
12 Correct 1563 ms 12156 KB Output is correct
13 Correct 1501 ms 12168 KB Output is correct
14 Correct 1470 ms 12100 KB Output is correct
15 Correct 1505 ms 12152 KB Output is correct
16 Correct 100 ms 2448 KB Output is correct
17 Correct 107 ms 2508 KB Output is correct
18 Correct 109 ms 2528 KB Output is correct
19 Correct 114 ms 2600 KB Output is correct
20 Correct 109 ms 2536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1430 ms 12316 KB Output is correct
2 Correct 1414 ms 12208 KB Output is correct
3 Correct 1434 ms 12188 KB Output is correct
4 Correct 1479 ms 12236 KB Output is correct
5 Correct 1448 ms 12060 KB Output is correct
6 Correct 1462 ms 12208 KB Output is correct
7 Correct 1471 ms 12152 KB Output is correct
8 Correct 1484 ms 12152 KB Output is correct
9 Correct 1447 ms 12240 KB Output is correct
10 Correct 1466 ms 12192 KB Output is correct
11 Correct 1457 ms 12380 KB Output is correct
12 Correct 1563 ms 12156 KB Output is correct
13 Correct 1501 ms 12168 KB Output is correct
14 Correct 1470 ms 12100 KB Output is correct
15 Correct 1505 ms 12152 KB Output is correct
16 Correct 100 ms 2448 KB Output is correct
17 Correct 107 ms 2508 KB Output is correct
18 Correct 109 ms 2528 KB Output is correct
19 Correct 114 ms 2600 KB Output is correct
20 Correct 109 ms 2536 KB Output is correct
21 Incorrect 1737 ms 11116 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 2664 KB Output is correct
2 Correct 16 ms 2700 KB Output is correct
3 Correct 17 ms 2636 KB Output is correct
4 Correct 17 ms 2628 KB Output is correct
5 Correct 18 ms 2624 KB Output is correct
6 Correct 22 ms 2712 KB Output is correct
7 Correct 20 ms 2624 KB Output is correct
8 Correct 19 ms 2628 KB Output is correct
9 Correct 19 ms 2636 KB Output is correct
10 Correct 22 ms 2640 KB Output is correct
11 Correct 19 ms 2732 KB Output is correct
12 Correct 19 ms 2636 KB Output is correct
13 Correct 18 ms 2724 KB Output is correct
14 Correct 16 ms 2636 KB Output is correct
15 Correct 17 ms 2628 KB Output is correct
16 Incorrect 8 ms 1740 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1430 ms 12316 KB Output is correct
2 Correct 1414 ms 12208 KB Output is correct
3 Correct 1434 ms 12188 KB Output is correct
4 Correct 1479 ms 12236 KB Output is correct
5 Correct 1448 ms 12060 KB Output is correct
6 Correct 1462 ms 12208 KB Output is correct
7 Correct 1471 ms 12152 KB Output is correct
8 Correct 1484 ms 12152 KB Output is correct
9 Correct 1447 ms 12240 KB Output is correct
10 Correct 1466 ms 12192 KB Output is correct
11 Correct 1457 ms 12380 KB Output is correct
12 Correct 1563 ms 12156 KB Output is correct
13 Correct 1501 ms 12168 KB Output is correct
14 Correct 1470 ms 12100 KB Output is correct
15 Correct 1505 ms 12152 KB Output is correct
16 Correct 100 ms 2448 KB Output is correct
17 Correct 107 ms 2508 KB Output is correct
18 Correct 109 ms 2528 KB Output is correct
19 Correct 114 ms 2600 KB Output is correct
20 Correct 109 ms 2536 KB Output is correct
21 Incorrect 1737 ms 11116 KB Output isn't correct
22 Halted 0 ms 0 KB -