Submission #249908

# Submission time Handle Problem Language Result Execution time Memory
249908 2020-07-16T12:18:04 Z receed Boat (APIO16_boat) C++14
100 / 100
600 ms 30972 KB
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cassert>
#include <string>
#include <set>
#include <map>
#include <random>
#include <bitset>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using ul = unsigned long long;
using ld = long double;

const int N = 1001;
const ll MOD = 1e9 + 7, M2 = MOD * MOD;
ll a[N], b[N], ps[N][N], c[N][N], cd[N][N], rev[N], cs[N][N], dp[N][N];

ll pw(ll x, ll k) {
    ll r = 1;
    while (k) {
        if (k & 1)
            r = r * x % MOD;
        k >>= 1;
        x = x * x % MOD;
    }
    return r;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n, d;
    cin >> n;
    vector<ll> li;
    rep(i, n) {
        cin >> a[i] >> b[i];
        b[i]++;
        li.push_back(a[i]);
        li.push_back(b[i]);
    }
    sort(all(li));
    li.resize(unique(all(li)) - li.begin());
    int m = li.size();
    rep(i, n) {
        a[i] = lower_bound(all(li), a[i]) - li.begin();
        b[i] = lower_bound(all(li), b[i]) - li.begin();
        rep(j, m)
            ps[j][i + 1] = ps[j][i] + (a[i] <= j && j < b[i]);
    }
    rep(i, n + 1) {
        c[i][0] = 1;
        for (int j = 1; j <= i; j++)
            c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;
        rev[i] = pw(i, MOD - 2);
    }
    rep(i, m - 1) {
        d = li[i + 1] - li[i];
        cd[i][1] = d;
        for (int j = 1; j < n; j++)
            cd[i][j + 1] = cd[i][j] * (d - j) % MOD * rev[j + 1] % MOD;
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= j; k++) {
                cs[i][j] += c[j - 1][k - 1] * cd[i][k];
                if (cs[i][j] >= M2)
                    cs[i][j] -= M2;
            }
            cs[i][j] %= MOD;
        }
    }
    rep(i, n) {
        for (int j = a[i]; j < b[i]; j++) {
            dp[i + 1][j] = cs[j][ps[j][i + 1]];
            if (j)
                rep(k, i + 1) {
                    dp[i + 1][j] += dp[k][j - 1] * cs[j][ps[j][i + 1] - ps[j][k]];
                    if (dp[i + 1][j] >= M2)
                        dp[i + 1][j] -= M2;
                }
            dp[i + 1][j] %= MOD;
        }
        rep(j, m)
            dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i + 1][j + 1]) % MOD;
    }
    ll ans = 0;
    rep(i, n + 1) {
        ans = (ans + dp[i][m]) % MOD;
    }
    cout << ans;
}

# Verdict Execution time Memory Grader output
1 Correct 249 ms 30840 KB Output is correct
2 Correct 247 ms 30840 KB Output is correct
3 Correct 246 ms 30840 KB Output is correct
4 Correct 250 ms 30840 KB Output is correct
5 Correct 247 ms 30840 KB Output is correct
6 Correct 246 ms 30840 KB Output is correct
7 Correct 248 ms 30968 KB Output is correct
8 Correct 245 ms 30840 KB Output is correct
9 Correct 244 ms 30812 KB Output is correct
10 Correct 261 ms 30876 KB Output is correct
11 Correct 246 ms 30840 KB Output is correct
12 Correct 248 ms 30768 KB Output is correct
13 Correct 247 ms 30840 KB Output is correct
14 Correct 244 ms 30840 KB Output is correct
15 Correct 247 ms 30968 KB Output is correct
16 Correct 46 ms 10232 KB Output is correct
17 Correct 49 ms 10616 KB Output is correct
18 Correct 51 ms 10360 KB Output is correct
19 Correct 50 ms 10616 KB Output is correct
20 Correct 48 ms 10492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 249 ms 30840 KB Output is correct
2 Correct 247 ms 30840 KB Output is correct
3 Correct 246 ms 30840 KB Output is correct
4 Correct 250 ms 30840 KB Output is correct
5 Correct 247 ms 30840 KB Output is correct
6 Correct 246 ms 30840 KB Output is correct
7 Correct 248 ms 30968 KB Output is correct
8 Correct 245 ms 30840 KB Output is correct
9 Correct 244 ms 30812 KB Output is correct
10 Correct 261 ms 30876 KB Output is correct
11 Correct 246 ms 30840 KB Output is correct
12 Correct 248 ms 30768 KB Output is correct
13 Correct 247 ms 30840 KB Output is correct
14 Correct 244 ms 30840 KB Output is correct
15 Correct 247 ms 30968 KB Output is correct
16 Correct 46 ms 10232 KB Output is correct
17 Correct 49 ms 10616 KB Output is correct
18 Correct 51 ms 10360 KB Output is correct
19 Correct 50 ms 10616 KB Output is correct
20 Correct 48 ms 10492 KB Output is correct
21 Correct 352 ms 28664 KB Output is correct
22 Correct 354 ms 29048 KB Output is correct
23 Correct 328 ms 28664 KB Output is correct
24 Correct 321 ms 28408 KB Output is correct
25 Correct 329 ms 28680 KB Output is correct
26 Correct 361 ms 28024 KB Output is correct
27 Correct 378 ms 28408 KB Output is correct
28 Correct 364 ms 27896 KB Output is correct
29 Correct 357 ms 27896 KB Output is correct
30 Correct 254 ms 30716 KB Output is correct
31 Correct 246 ms 30840 KB Output is correct
32 Correct 248 ms 30972 KB Output is correct
33 Correct 248 ms 30840 KB Output is correct
34 Correct 243 ms 30712 KB Output is correct
35 Correct 256 ms 30712 KB Output is correct
36 Correct 252 ms 30712 KB Output is correct
37 Correct 253 ms 30712 KB Output is correct
38 Correct 255 ms 30712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4224 KB Output is correct
2 Correct 6 ms 4224 KB Output is correct
3 Correct 6 ms 4224 KB Output is correct
4 Correct 8 ms 4224 KB Output is correct
5 Correct 7 ms 4224 KB Output is correct
6 Correct 7 ms 4224 KB Output is correct
7 Correct 8 ms 4224 KB Output is correct
8 Correct 7 ms 4224 KB Output is correct
9 Correct 8 ms 4224 KB Output is correct
10 Correct 8 ms 4224 KB Output is correct
11 Correct 6 ms 4224 KB Output is correct
12 Correct 6 ms 4224 KB Output is correct
13 Correct 6 ms 4224 KB Output is correct
14 Correct 6 ms 4224 KB Output is correct
15 Correct 6 ms 4224 KB Output is correct
16 Correct 4 ms 2944 KB Output is correct
17 Correct 4 ms 2944 KB Output is correct
18 Correct 4 ms 2944 KB Output is correct
19 Correct 4 ms 2944 KB Output is correct
20 Correct 4 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 249 ms 30840 KB Output is correct
2 Correct 247 ms 30840 KB Output is correct
3 Correct 246 ms 30840 KB Output is correct
4 Correct 250 ms 30840 KB Output is correct
5 Correct 247 ms 30840 KB Output is correct
6 Correct 246 ms 30840 KB Output is correct
7 Correct 248 ms 30968 KB Output is correct
8 Correct 245 ms 30840 KB Output is correct
9 Correct 244 ms 30812 KB Output is correct
10 Correct 261 ms 30876 KB Output is correct
11 Correct 246 ms 30840 KB Output is correct
12 Correct 248 ms 30768 KB Output is correct
13 Correct 247 ms 30840 KB Output is correct
14 Correct 244 ms 30840 KB Output is correct
15 Correct 247 ms 30968 KB Output is correct
16 Correct 46 ms 10232 KB Output is correct
17 Correct 49 ms 10616 KB Output is correct
18 Correct 51 ms 10360 KB Output is correct
19 Correct 50 ms 10616 KB Output is correct
20 Correct 48 ms 10492 KB Output is correct
21 Correct 352 ms 28664 KB Output is correct
22 Correct 354 ms 29048 KB Output is correct
23 Correct 328 ms 28664 KB Output is correct
24 Correct 321 ms 28408 KB Output is correct
25 Correct 329 ms 28680 KB Output is correct
26 Correct 361 ms 28024 KB Output is correct
27 Correct 378 ms 28408 KB Output is correct
28 Correct 364 ms 27896 KB Output is correct
29 Correct 357 ms 27896 KB Output is correct
30 Correct 254 ms 30716 KB Output is correct
31 Correct 246 ms 30840 KB Output is correct
32 Correct 248 ms 30972 KB Output is correct
33 Correct 248 ms 30840 KB Output is correct
34 Correct 243 ms 30712 KB Output is correct
35 Correct 256 ms 30712 KB Output is correct
36 Correct 252 ms 30712 KB Output is correct
37 Correct 253 ms 30712 KB Output is correct
38 Correct 255 ms 30712 KB Output is correct
39 Correct 6 ms 4224 KB Output is correct
40 Correct 6 ms 4224 KB Output is correct
41 Correct 6 ms 4224 KB Output is correct
42 Correct 8 ms 4224 KB Output is correct
43 Correct 7 ms 4224 KB Output is correct
44 Correct 7 ms 4224 KB Output is correct
45 Correct 8 ms 4224 KB Output is correct
46 Correct 7 ms 4224 KB Output is correct
47 Correct 8 ms 4224 KB Output is correct
48 Correct 8 ms 4224 KB Output is correct
49 Correct 6 ms 4224 KB Output is correct
50 Correct 6 ms 4224 KB Output is correct
51 Correct 6 ms 4224 KB Output is correct
52 Correct 6 ms 4224 KB Output is correct
53 Correct 6 ms 4224 KB Output is correct
54 Correct 4 ms 2944 KB Output is correct
55 Correct 4 ms 2944 KB Output is correct
56 Correct 4 ms 2944 KB Output is correct
57 Correct 4 ms 2944 KB Output is correct
58 Correct 4 ms 2816 KB Output is correct
59 Correct 449 ms 30908 KB Output is correct
60 Correct 433 ms 30840 KB Output is correct
61 Correct 443 ms 30964 KB Output is correct
62 Correct 446 ms 30840 KB Output is correct
63 Correct 435 ms 30840 KB Output is correct
64 Correct 585 ms 30848 KB Output is correct
65 Correct 566 ms 30768 KB Output is correct
66 Correct 600 ms 30840 KB Output is correct
67 Correct 595 ms 30840 KB Output is correct
68 Correct 591 ms 30840 KB Output is correct
69 Correct 419 ms 30840 KB Output is correct
70 Correct 431 ms 30824 KB Output is correct
71 Correct 406 ms 30840 KB Output is correct
72 Correct 435 ms 30880 KB Output is correct
73 Correct 449 ms 30840 KB Output is correct
74 Correct 70 ms 10360 KB Output is correct
75 Correct 71 ms 10488 KB Output is correct
76 Correct 71 ms 10360 KB Output is correct
77 Correct 73 ms 10360 KB Output is correct
78 Correct 72 ms 10360 KB Output is correct