답안 #545636

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
545636 2022-04-05T04:29:14 Z flashhh Boat (APIO16_boat) C++14
100 / 100
481 ms 16244 KB
#include <bits/stdc++.h>
#define ll long long
#define N 505
#define pii pair<int,int>
#define fi first
#define se second
#define pb emplace_back

const int oo = 1e9 + 7;

using namespace std;

int n,m;
pii a[N],b[N*4];
ll res,inv[N],dp[N][N*4],pre[N][N*4];
vector<int> lvt;

ll power(ll x,int y) {
    if (y == 0) return 1;

    ll tam = power(x*x %oo, y>>1);
    if (y&1) tam = tam * x %oo;

    return tam;
}

int main()
{
    //freopen(".inp","r",stdin);
    //freopen(".out","w",stdout);
    ios_base::sync_with_stdio (0); cin.tie (0); cout.tie (0);

    cin >> n;
    for (int i=1;i<=n;++i) {
        cin >> a[i].fi >> a[i].se;
        lvt.pb(a[i].fi); lvt.pb(a[i].se);
    }

    sort(lvt.begin(),lvt.end());
    lvt.resize(unique(lvt.begin(),lvt.end())-lvt.begin());

    for (int e=0;e<(int)lvt.size();++e) {
        b[++m] = {lvt[e],lvt[e]};
        if (e < (int)lvt.size() - 1 && lvt[e]+1 < lvt[e+1]) b[++m] = {lvt[e]+1,lvt[e+1]-1};
    }

    dp[0][0] = 1;
    for (int i=0;i<=n;++i) pre[i][0] = 1;
    for (int j=0;j<=m;++j) pre[0][j] = 1;

    for (int i=1;i<=n+2;++i) inv[i] = power(i,oo-2);

    for (int i=1;i<=n;++i)
        for (int j=1;j<=m;++j) {
            dp[i][j] = dp[i][j-1];
            if (a[i].fi > b[j].se || a[i].se < b[j].fi) {
                pre[i][j] = (pre[i-1][j] + dp[i][j]) %oo;
                continue;
            }

            int len = b[j].se - b[j].fi + 1; int num = -1;
            ll C = len - 1;

            dp[i][j] = (dp[i][j] + pre[i-1][j-1] * len) %oo;

            if (len >= 2) {
                for (int k=2;k<=i;++k) {
                    if (a[i-k+1].fi > b[j].se || a[i-k+1].se < b[j].fi) continue;

                    ++num;
                    C = C * (num + len) %oo * inv[num+2] %oo;

                    dp[i][j] = (dp[i][j] + pre[i-k][j-1] * C) %oo;
                }
            }

            pre[i][j] = (pre[i-1][j] + dp[i][j]) %oo;
        }

    for (int i=1;i<=n;++i) res = (res + dp[i][m]) %oo;
    cout << res;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12064 KB Output is correct
2 Correct 7 ms 12116 KB Output is correct
3 Correct 7 ms 12116 KB Output is correct
4 Correct 7 ms 12080 KB Output is correct
5 Correct 7 ms 12116 KB Output is correct
6 Correct 7 ms 12108 KB Output is correct
7 Correct 7 ms 12116 KB Output is correct
8 Correct 7 ms 12152 KB Output is correct
9 Correct 7 ms 12116 KB Output is correct
10 Correct 7 ms 12108 KB Output is correct
11 Correct 7 ms 12116 KB Output is correct
12 Correct 7 ms 12116 KB Output is correct
13 Correct 7 ms 12116 KB Output is correct
14 Correct 7 ms 12112 KB Output is correct
15 Correct 7 ms 12116 KB Output is correct
16 Correct 3 ms 5716 KB Output is correct
17 Correct 3 ms 5844 KB Output is correct
18 Correct 3 ms 5716 KB Output is correct
19 Correct 3 ms 5836 KB Output is correct
20 Correct 3 ms 5708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12064 KB Output is correct
2 Correct 7 ms 12116 KB Output is correct
3 Correct 7 ms 12116 KB Output is correct
4 Correct 7 ms 12080 KB Output is correct
5 Correct 7 ms 12116 KB Output is correct
6 Correct 7 ms 12108 KB Output is correct
7 Correct 7 ms 12116 KB Output is correct
8 Correct 7 ms 12152 KB Output is correct
9 Correct 7 ms 12116 KB Output is correct
10 Correct 7 ms 12108 KB Output is correct
11 Correct 7 ms 12116 KB Output is correct
12 Correct 7 ms 12116 KB Output is correct
13 Correct 7 ms 12116 KB Output is correct
14 Correct 7 ms 12112 KB Output is correct
15 Correct 7 ms 12116 KB Output is correct
16 Correct 3 ms 5716 KB Output is correct
17 Correct 3 ms 5844 KB Output is correct
18 Correct 3 ms 5716 KB Output is correct
19 Correct 3 ms 5836 KB Output is correct
20 Correct 3 ms 5708 KB Output is correct
21 Correct 141 ms 16204 KB Output is correct
22 Correct 137 ms 16140 KB Output is correct
23 Correct 122 ms 16136 KB Output is correct
24 Correct 140 ms 16128 KB Output is correct
25 Correct 143 ms 16088 KB Output is correct
26 Correct 249 ms 16096 KB Output is correct
27 Correct 258 ms 16136 KB Output is correct
28 Correct 260 ms 16108 KB Output is correct
29 Correct 271 ms 16120 KB Output is correct
30 Correct 10 ms 16084 KB Output is correct
31 Correct 10 ms 16084 KB Output is correct
32 Correct 9 ms 16084 KB Output is correct
33 Correct 11 ms 16084 KB Output is correct
34 Correct 9 ms 16164 KB Output is correct
35 Correct 7 ms 12116 KB Output is correct
36 Correct 8 ms 12068 KB Output is correct
37 Correct 7 ms 12116 KB Output is correct
38 Correct 8 ms 12116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1748 KB Output is correct
2 Correct 2 ms 1748 KB Output is correct
3 Correct 2 ms 1748 KB Output is correct
4 Correct 3 ms 1748 KB Output is correct
5 Correct 3 ms 1748 KB Output is correct
6 Correct 5 ms 1748 KB Output is correct
7 Correct 5 ms 1748 KB Output is correct
8 Correct 5 ms 1748 KB Output is correct
9 Correct 6 ms 1724 KB Output is correct
10 Correct 5 ms 1748 KB Output is correct
11 Correct 3 ms 1748 KB Output is correct
12 Correct 2 ms 1748 KB Output is correct
13 Correct 3 ms 1748 KB Output is correct
14 Correct 2 ms 1748 KB Output is correct
15 Correct 3 ms 1748 KB Output is correct
16 Correct 2 ms 1364 KB Output is correct
17 Correct 2 ms 1364 KB Output is correct
18 Correct 2 ms 1364 KB Output is correct
19 Correct 2 ms 1364 KB Output is correct
20 Correct 2 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12064 KB Output is correct
2 Correct 7 ms 12116 KB Output is correct
3 Correct 7 ms 12116 KB Output is correct
4 Correct 7 ms 12080 KB Output is correct
5 Correct 7 ms 12116 KB Output is correct
6 Correct 7 ms 12108 KB Output is correct
7 Correct 7 ms 12116 KB Output is correct
8 Correct 7 ms 12152 KB Output is correct
9 Correct 7 ms 12116 KB Output is correct
10 Correct 7 ms 12108 KB Output is correct
11 Correct 7 ms 12116 KB Output is correct
12 Correct 7 ms 12116 KB Output is correct
13 Correct 7 ms 12116 KB Output is correct
14 Correct 7 ms 12112 KB Output is correct
15 Correct 7 ms 12116 KB Output is correct
16 Correct 3 ms 5716 KB Output is correct
17 Correct 3 ms 5844 KB Output is correct
18 Correct 3 ms 5716 KB Output is correct
19 Correct 3 ms 5836 KB Output is correct
20 Correct 3 ms 5708 KB Output is correct
21 Correct 141 ms 16204 KB Output is correct
22 Correct 137 ms 16140 KB Output is correct
23 Correct 122 ms 16136 KB Output is correct
24 Correct 140 ms 16128 KB Output is correct
25 Correct 143 ms 16088 KB Output is correct
26 Correct 249 ms 16096 KB Output is correct
27 Correct 258 ms 16136 KB Output is correct
28 Correct 260 ms 16108 KB Output is correct
29 Correct 271 ms 16120 KB Output is correct
30 Correct 10 ms 16084 KB Output is correct
31 Correct 10 ms 16084 KB Output is correct
32 Correct 9 ms 16084 KB Output is correct
33 Correct 11 ms 16084 KB Output is correct
34 Correct 9 ms 16164 KB Output is correct
35 Correct 7 ms 12116 KB Output is correct
36 Correct 8 ms 12068 KB Output is correct
37 Correct 7 ms 12116 KB Output is correct
38 Correct 8 ms 12116 KB Output is correct
39 Correct 3 ms 1748 KB Output is correct
40 Correct 2 ms 1748 KB Output is correct
41 Correct 2 ms 1748 KB Output is correct
42 Correct 3 ms 1748 KB Output is correct
43 Correct 3 ms 1748 KB Output is correct
44 Correct 5 ms 1748 KB Output is correct
45 Correct 5 ms 1748 KB Output is correct
46 Correct 5 ms 1748 KB Output is correct
47 Correct 6 ms 1724 KB Output is correct
48 Correct 5 ms 1748 KB Output is correct
49 Correct 3 ms 1748 KB Output is correct
50 Correct 2 ms 1748 KB Output is correct
51 Correct 3 ms 1748 KB Output is correct
52 Correct 2 ms 1748 KB Output is correct
53 Correct 3 ms 1748 KB Output is correct
54 Correct 2 ms 1364 KB Output is correct
55 Correct 2 ms 1364 KB Output is correct
56 Correct 2 ms 1364 KB Output is correct
57 Correct 2 ms 1364 KB Output is correct
58 Correct 2 ms 1364 KB Output is correct
59 Correct 213 ms 16076 KB Output is correct
60 Correct 196 ms 16188 KB Output is correct
61 Correct 182 ms 16068 KB Output is correct
62 Correct 217 ms 16140 KB Output is correct
63 Correct 202 ms 16076 KB Output is correct
64 Correct 477 ms 16076 KB Output is correct
65 Correct 476 ms 16128 KB Output is correct
66 Correct 474 ms 16244 KB Output is correct
67 Correct 473 ms 16140 KB Output is correct
68 Correct 481 ms 16132 KB Output is correct
69 Correct 175 ms 16076 KB Output is correct
70 Correct 181 ms 16204 KB Output is correct
71 Correct 178 ms 16064 KB Output is correct
72 Correct 187 ms 16072 KB Output is correct
73 Correct 190 ms 16128 KB Output is correct
74 Correct 26 ms 5848 KB Output is correct
75 Correct 23 ms 5832 KB Output is correct
76 Correct 25 ms 5836 KB Output is correct
77 Correct 25 ms 5904 KB Output is correct
78 Correct 25 ms 5828 KB Output is correct