답안 #758709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
758709 2023-06-15T07:41:04 Z Trisanu_Das Boat (APIO16_boat) C++17
100 / 100
657 ms 4404 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 178 ms 4300 KB Output is correct
2 Correct 180 ms 4300 KB Output is correct
3 Correct 178 ms 4320 KB Output is correct
4 Correct 186 ms 4224 KB Output is correct
5 Correct 177 ms 4264 KB Output is correct
6 Correct 154 ms 4376 KB Output is correct
7 Correct 140 ms 4264 KB Output is correct
8 Correct 147 ms 4268 KB Output is correct
9 Correct 152 ms 4268 KB Output is correct
10 Correct 145 ms 4232 KB Output is correct
11 Correct 143 ms 4272 KB Output is correct
12 Correct 146 ms 4240 KB Output is correct
13 Correct 146 ms 4296 KB Output is correct
14 Correct 136 ms 4220 KB Output is correct
15 Correct 144 ms 4236 KB Output is correct
16 Correct 32 ms 960 KB Output is correct
17 Correct 34 ms 988 KB Output is correct
18 Correct 33 ms 1040 KB Output is correct
19 Correct 34 ms 992 KB Output is correct
20 Correct 33 ms 992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 178 ms 4300 KB Output is correct
2 Correct 180 ms 4300 KB Output is correct
3 Correct 178 ms 4320 KB Output is correct
4 Correct 186 ms 4224 KB Output is correct
5 Correct 177 ms 4264 KB Output is correct
6 Correct 154 ms 4376 KB Output is correct
7 Correct 140 ms 4264 KB Output is correct
8 Correct 147 ms 4268 KB Output is correct
9 Correct 152 ms 4268 KB Output is correct
10 Correct 145 ms 4232 KB Output is correct
11 Correct 143 ms 4272 KB Output is correct
12 Correct 146 ms 4240 KB Output is correct
13 Correct 146 ms 4296 KB Output is correct
14 Correct 136 ms 4220 KB Output is correct
15 Correct 144 ms 4236 KB Output is correct
16 Correct 32 ms 960 KB Output is correct
17 Correct 34 ms 988 KB Output is correct
18 Correct 33 ms 1040 KB Output is correct
19 Correct 34 ms 992 KB Output is correct
20 Correct 33 ms 992 KB Output is correct
21 Correct 386 ms 4156 KB Output is correct
22 Correct 386 ms 3912 KB Output is correct
23 Correct 363 ms 3908 KB Output is correct
24 Correct 376 ms 3916 KB Output is correct
25 Correct 400 ms 3908 KB Output is correct
26 Correct 571 ms 3812 KB Output is correct
27 Correct 584 ms 3848 KB Output is correct
28 Correct 573 ms 3980 KB Output is correct
29 Correct 569 ms 3752 KB Output is correct
30 Correct 148 ms 4224 KB Output is correct
31 Correct 140 ms 4244 KB Output is correct
32 Correct 143 ms 4296 KB Output is correct
33 Correct 140 ms 4236 KB Output is correct
34 Correct 139 ms 4220 KB Output is correct
35 Correct 178 ms 4216 KB Output is correct
36 Correct 182 ms 4312 KB Output is correct
37 Correct 185 ms 4232 KB Output is correct
38 Correct 178 ms 4248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1108 KB Output is correct
2 Correct 4 ms 1108 KB Output is correct
3 Correct 4 ms 1108 KB Output is correct
4 Correct 4 ms 1108 KB Output is correct
5 Correct 5 ms 1108 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 6 ms 1096 KB Output is correct
8 Correct 6 ms 1096 KB Output is correct
9 Correct 6 ms 1108 KB Output is correct
10 Correct 6 ms 1108 KB Output is correct
11 Correct 5 ms 1108 KB Output is correct
12 Correct 4 ms 1092 KB Output is correct
13 Correct 5 ms 1108 KB Output is correct
14 Correct 7 ms 1108 KB Output is correct
15 Correct 5 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 178 ms 4300 KB Output is correct
2 Correct 180 ms 4300 KB Output is correct
3 Correct 178 ms 4320 KB Output is correct
4 Correct 186 ms 4224 KB Output is correct
5 Correct 177 ms 4264 KB Output is correct
6 Correct 154 ms 4376 KB Output is correct
7 Correct 140 ms 4264 KB Output is correct
8 Correct 147 ms 4268 KB Output is correct
9 Correct 152 ms 4268 KB Output is correct
10 Correct 145 ms 4232 KB Output is correct
11 Correct 143 ms 4272 KB Output is correct
12 Correct 146 ms 4240 KB Output is correct
13 Correct 146 ms 4296 KB Output is correct
14 Correct 136 ms 4220 KB Output is correct
15 Correct 144 ms 4236 KB Output is correct
16 Correct 32 ms 960 KB Output is correct
17 Correct 34 ms 988 KB Output is correct
18 Correct 33 ms 1040 KB Output is correct
19 Correct 34 ms 992 KB Output is correct
20 Correct 33 ms 992 KB Output is correct
21 Correct 386 ms 4156 KB Output is correct
22 Correct 386 ms 3912 KB Output is correct
23 Correct 363 ms 3908 KB Output is correct
24 Correct 376 ms 3916 KB Output is correct
25 Correct 400 ms 3908 KB Output is correct
26 Correct 571 ms 3812 KB Output is correct
27 Correct 584 ms 3848 KB Output is correct
28 Correct 573 ms 3980 KB Output is correct
29 Correct 569 ms 3752 KB Output is correct
30 Correct 148 ms 4224 KB Output is correct
31 Correct 140 ms 4244 KB Output is correct
32 Correct 143 ms 4296 KB Output is correct
33 Correct 140 ms 4236 KB Output is correct
34 Correct 139 ms 4220 KB Output is correct
35 Correct 178 ms 4216 KB Output is correct
36 Correct 182 ms 4312 KB Output is correct
37 Correct 185 ms 4232 KB Output is correct
38 Correct 178 ms 4248 KB Output is correct
39 Correct 4 ms 1108 KB Output is correct
40 Correct 4 ms 1108 KB Output is correct
41 Correct 4 ms 1108 KB Output is correct
42 Correct 4 ms 1108 KB Output is correct
43 Correct 5 ms 1108 KB Output is correct
44 Correct 6 ms 1108 KB Output is correct
45 Correct 6 ms 1096 KB Output is correct
46 Correct 6 ms 1096 KB Output is correct
47 Correct 6 ms 1108 KB Output is correct
48 Correct 6 ms 1108 KB Output is correct
49 Correct 5 ms 1108 KB Output is correct
50 Correct 4 ms 1092 KB Output is correct
51 Correct 5 ms 1108 KB Output is correct
52 Correct 7 ms 1108 KB Output is correct
53 Correct 5 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 433 ms 4304 KB Output is correct
60 Correct 411 ms 4344 KB Output is correct
61 Correct 405 ms 4232 KB Output is correct
62 Correct 433 ms 4220 KB Output is correct
63 Correct 420 ms 4300 KB Output is correct
64 Correct 657 ms 4256 KB Output is correct
65 Correct 650 ms 4300 KB Output is correct
66 Correct 652 ms 4324 KB Output is correct
67 Correct 655 ms 4404 KB Output is correct
68 Correct 648 ms 4232 KB Output is correct
69 Correct 474 ms 4324 KB Output is correct
70 Correct 497 ms 4240 KB Output is correct
71 Correct 494 ms 4256 KB Output is correct
72 Correct 502 ms 4300 KB Output is correct
73 Correct 495 ms 4224 KB Output is correct
74 Correct 80 ms 972 KB Output is correct
75 Correct 83 ms 976 KB Output is correct
76 Correct 83 ms 1032 KB Output is correct
77 Correct 83 ms 960 KB Output is correct
78 Correct 81 ms 992 KB Output is correct