답안 #573748

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
573748 2022-06-07T06:53:20 Z Hanksburger Boat (APIO16_boat) C++17
100 / 100
758 ms 4548 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
int dp[1005][505], inv[505], a[505], b[505], c[1005];
set<int> s;
int f(int x, int y)
{
    if (!y)
        return 1;
    int res=f(x, y/2);
    if (y&1)
        return res*res%mod*x%mod;
    else
        return res*res%mod;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m=0;
    cin >> n;
    for (int i=1; i<=n; i++)
        inv[i]=f(i, mod-2);
    for (int i=1; i<=n; i++)
    {
        cin >> a[i] >> b[i];
        s.insert(a[i]);
        s.insert(b[i]+1);
    }
    for (auto itr=s.begin(); itr!=s.end(); itr++)
        c[++m]=(*itr);
    for (int i=0; i<=n; i++)
        dp[0][i]=1;
    for (int i=1; i<m; i++)
    {
        for (int j=0; j<=n; j++)
        {
            dp[i][j]=dp[i-1][j];
            int num=1, cnt=0;
            for (int k=1; k<=j; k++)
            {
                if (a[j-k+1]<=c[i] && c[i+1]-1<=b[j-k+1])
                {
                    cnt++;
                    num=num*(c[i+1]-c[i]+cnt-1)%mod*inv[cnt]%mod;
                    dp[i][j]=(dp[i][j]+dp[i-1][j-k]*num)%mod;
                }
            }
        }
    }
    cout << dp[m-1][n]-1;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 257 ms 4228 KB Output is correct
2 Correct 241 ms 4320 KB Output is correct
3 Correct 262 ms 4232 KB Output is correct
4 Correct 237 ms 4292 KB Output is correct
5 Correct 240 ms 4300 KB Output is correct
6 Correct 168 ms 4300 KB Output is correct
7 Correct 154 ms 4300 KB Output is correct
8 Correct 160 ms 4316 KB Output is correct
9 Correct 197 ms 4220 KB Output is correct
10 Correct 161 ms 4224 KB Output is correct
11 Correct 167 ms 4220 KB Output is correct
12 Correct 208 ms 4304 KB Output is correct
13 Correct 163 ms 4316 KB Output is correct
14 Correct 153 ms 4284 KB Output is correct
15 Correct 161 ms 4228 KB Output is correct
16 Correct 51 ms 972 KB Output is correct
17 Correct 44 ms 1084 KB Output is correct
18 Correct 56 ms 968 KB Output is correct
19 Correct 44 ms 988 KB Output is correct
20 Correct 43 ms 976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 257 ms 4228 KB Output is correct
2 Correct 241 ms 4320 KB Output is correct
3 Correct 262 ms 4232 KB Output is correct
4 Correct 237 ms 4292 KB Output is correct
5 Correct 240 ms 4300 KB Output is correct
6 Correct 168 ms 4300 KB Output is correct
7 Correct 154 ms 4300 KB Output is correct
8 Correct 160 ms 4316 KB Output is correct
9 Correct 197 ms 4220 KB Output is correct
10 Correct 161 ms 4224 KB Output is correct
11 Correct 167 ms 4220 KB Output is correct
12 Correct 208 ms 4304 KB Output is correct
13 Correct 163 ms 4316 KB Output is correct
14 Correct 153 ms 4284 KB Output is correct
15 Correct 161 ms 4228 KB Output is correct
16 Correct 51 ms 972 KB Output is correct
17 Correct 44 ms 1084 KB Output is correct
18 Correct 56 ms 968 KB Output is correct
19 Correct 44 ms 988 KB Output is correct
20 Correct 43 ms 976 KB Output is correct
21 Correct 465 ms 4112 KB Output is correct
22 Correct 428 ms 3924 KB Output is correct
23 Correct 445 ms 3888 KB Output is correct
24 Correct 419 ms 3860 KB Output is correct
25 Correct 492 ms 3892 KB Output is correct
26 Correct 666 ms 3972 KB Output is correct
27 Correct 671 ms 3904 KB Output is correct
28 Correct 657 ms 3808 KB Output is correct
29 Correct 666 ms 3740 KB Output is correct
30 Correct 170 ms 4404 KB Output is correct
31 Correct 167 ms 4312 KB Output is correct
32 Correct 165 ms 4300 KB Output is correct
33 Correct 162 ms 4216 KB Output is correct
34 Correct 184 ms 4268 KB Output is correct
35 Correct 262 ms 4220 KB Output is correct
36 Correct 243 ms 4304 KB Output is correct
37 Correct 246 ms 4408 KB Output is correct
38 Correct 269 ms 4188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1108 KB Output is correct
2 Correct 4 ms 1056 KB Output is correct
3 Correct 5 ms 1012 KB Output is correct
4 Correct 5 ms 1060 KB Output is correct
5 Correct 5 ms 1108 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 6 ms 1108 KB Output is correct
8 Correct 8 ms 1108 KB Output is correct
9 Correct 7 ms 1128 KB Output is correct
10 Correct 8 ms 1124 KB Output is correct
11 Correct 6 ms 1108 KB Output is correct
12 Correct 6 ms 1028 KB Output is correct
13 Correct 6 ms 1108 KB Output is correct
14 Correct 5 ms 1108 KB Output is correct
15 Correct 6 ms 1108 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 3 ms 724 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 257 ms 4228 KB Output is correct
2 Correct 241 ms 4320 KB Output is correct
3 Correct 262 ms 4232 KB Output is correct
4 Correct 237 ms 4292 KB Output is correct
5 Correct 240 ms 4300 KB Output is correct
6 Correct 168 ms 4300 KB Output is correct
7 Correct 154 ms 4300 KB Output is correct
8 Correct 160 ms 4316 KB Output is correct
9 Correct 197 ms 4220 KB Output is correct
10 Correct 161 ms 4224 KB Output is correct
11 Correct 167 ms 4220 KB Output is correct
12 Correct 208 ms 4304 KB Output is correct
13 Correct 163 ms 4316 KB Output is correct
14 Correct 153 ms 4284 KB Output is correct
15 Correct 161 ms 4228 KB Output is correct
16 Correct 51 ms 972 KB Output is correct
17 Correct 44 ms 1084 KB Output is correct
18 Correct 56 ms 968 KB Output is correct
19 Correct 44 ms 988 KB Output is correct
20 Correct 43 ms 976 KB Output is correct
21 Correct 465 ms 4112 KB Output is correct
22 Correct 428 ms 3924 KB Output is correct
23 Correct 445 ms 3888 KB Output is correct
24 Correct 419 ms 3860 KB Output is correct
25 Correct 492 ms 3892 KB Output is correct
26 Correct 666 ms 3972 KB Output is correct
27 Correct 671 ms 3904 KB Output is correct
28 Correct 657 ms 3808 KB Output is correct
29 Correct 666 ms 3740 KB Output is correct
30 Correct 170 ms 4404 KB Output is correct
31 Correct 167 ms 4312 KB Output is correct
32 Correct 165 ms 4300 KB Output is correct
33 Correct 162 ms 4216 KB Output is correct
34 Correct 184 ms 4268 KB Output is correct
35 Correct 262 ms 4220 KB Output is correct
36 Correct 243 ms 4304 KB Output is correct
37 Correct 246 ms 4408 KB Output is correct
38 Correct 269 ms 4188 KB Output is correct
39 Correct 5 ms 1108 KB Output is correct
40 Correct 4 ms 1056 KB Output is correct
41 Correct 5 ms 1012 KB Output is correct
42 Correct 5 ms 1060 KB Output is correct
43 Correct 5 ms 1108 KB Output is correct
44 Correct 7 ms 1108 KB Output is correct
45 Correct 6 ms 1108 KB Output is correct
46 Correct 8 ms 1108 KB Output is correct
47 Correct 7 ms 1128 KB Output is correct
48 Correct 8 ms 1124 KB Output is correct
49 Correct 6 ms 1108 KB Output is correct
50 Correct 6 ms 1028 KB Output is correct
51 Correct 6 ms 1108 KB Output is correct
52 Correct 5 ms 1108 KB Output is correct
53 Correct 6 ms 1108 KB Output is correct
54 Correct 3 ms 724 KB Output is correct
55 Correct 3 ms 724 KB Output is correct
56 Correct 3 ms 724 KB Output is correct
57 Correct 3 ms 724 KB Output is correct
58 Correct 3 ms 724 KB Output is correct
59 Correct 520 ms 4360 KB Output is correct
60 Correct 464 ms 4272 KB Output is correct
61 Correct 480 ms 4204 KB Output is correct
62 Correct 502 ms 4228 KB Output is correct
63 Correct 478 ms 4292 KB Output is correct
64 Correct 758 ms 4300 KB Output is correct
65 Correct 736 ms 4292 KB Output is correct
66 Correct 738 ms 4548 KB Output is correct
67 Correct 732 ms 4348 KB Output is correct
68 Correct 747 ms 4304 KB Output is correct
69 Correct 546 ms 4296 KB Output is correct
70 Correct 581 ms 4224 KB Output is correct
71 Correct 590 ms 4500 KB Output is correct
72 Correct 580 ms 4256 KB Output is correct
73 Correct 563 ms 4340 KB Output is correct
74 Correct 96 ms 972 KB Output is correct
75 Correct 96 ms 960 KB Output is correct
76 Correct 91 ms 968 KB Output is correct
77 Correct 93 ms 1036 KB Output is correct
78 Correct 99 ms 1004 KB Output is correct