# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
573747 |
2022-06-07T06:51:18 Z |
Hanksburger |
Boat (APIO16_boat) |
C++17 |
|
752 ms |
4372 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];
// cout << "--------- i j " << i << ' ' << j << ' ' << dp[i][j] << '\n';
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 << "i j k " << i << ' ' << j << ' ' << k << ' ' << dp[i][j] << '\n';
}
}
}
cout << dp[m-1][n]-1;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
279 ms |
4288 KB |
Output is correct |
2 |
Correct |
320 ms |
4320 KB |
Output is correct |
3 |
Correct |
295 ms |
4228 KB |
Output is correct |
4 |
Correct |
267 ms |
4220 KB |
Output is correct |
5 |
Correct |
322 ms |
4336 KB |
Output is correct |
6 |
Correct |
194 ms |
4332 KB |
Output is correct |
7 |
Correct |
202 ms |
4272 KB |
Output is correct |
8 |
Correct |
233 ms |
4268 KB |
Output is correct |
9 |
Correct |
218 ms |
4332 KB |
Output is correct |
10 |
Correct |
223 ms |
4320 KB |
Output is correct |
11 |
Correct |
223 ms |
4316 KB |
Output is correct |
12 |
Correct |
192 ms |
4292 KB |
Output is correct |
13 |
Correct |
237 ms |
4332 KB |
Output is correct |
14 |
Correct |
190 ms |
4324 KB |
Output is correct |
15 |
Correct |
194 ms |
4224 KB |
Output is correct |
16 |
Correct |
46 ms |
1032 KB |
Output is correct |
17 |
Correct |
48 ms |
1060 KB |
Output is correct |
18 |
Correct |
48 ms |
1004 KB |
Output is correct |
19 |
Correct |
50 ms |
1064 KB |
Output is correct |
20 |
Correct |
51 ms |
1080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
279 ms |
4288 KB |
Output is correct |
2 |
Correct |
320 ms |
4320 KB |
Output is correct |
3 |
Correct |
295 ms |
4228 KB |
Output is correct |
4 |
Correct |
267 ms |
4220 KB |
Output is correct |
5 |
Correct |
322 ms |
4336 KB |
Output is correct |
6 |
Correct |
194 ms |
4332 KB |
Output is correct |
7 |
Correct |
202 ms |
4272 KB |
Output is correct |
8 |
Correct |
233 ms |
4268 KB |
Output is correct |
9 |
Correct |
218 ms |
4332 KB |
Output is correct |
10 |
Correct |
223 ms |
4320 KB |
Output is correct |
11 |
Correct |
223 ms |
4316 KB |
Output is correct |
12 |
Correct |
192 ms |
4292 KB |
Output is correct |
13 |
Correct |
237 ms |
4332 KB |
Output is correct |
14 |
Correct |
190 ms |
4324 KB |
Output is correct |
15 |
Correct |
194 ms |
4224 KB |
Output is correct |
16 |
Correct |
46 ms |
1032 KB |
Output is correct |
17 |
Correct |
48 ms |
1060 KB |
Output is correct |
18 |
Correct |
48 ms |
1004 KB |
Output is correct |
19 |
Correct |
50 ms |
1064 KB |
Output is correct |
20 |
Correct |
51 ms |
1080 KB |
Output is correct |
21 |
Correct |
513 ms |
3920 KB |
Output is correct |
22 |
Correct |
485 ms |
4020 KB |
Output is correct |
23 |
Correct |
468 ms |
3920 KB |
Output is correct |
24 |
Correct |
489 ms |
3808 KB |
Output is correct |
25 |
Correct |
522 ms |
3880 KB |
Output is correct |
26 |
Correct |
701 ms |
3772 KB |
Output is correct |
27 |
Correct |
749 ms |
3812 KB |
Output is correct |
28 |
Correct |
704 ms |
3756 KB |
Output is correct |
29 |
Correct |
695 ms |
3744 KB |
Output is correct |
30 |
Correct |
187 ms |
4324 KB |
Output is correct |
31 |
Correct |
181 ms |
4292 KB |
Output is correct |
32 |
Correct |
182 ms |
4200 KB |
Output is correct |
33 |
Correct |
191 ms |
4260 KB |
Output is correct |
34 |
Correct |
179 ms |
4252 KB |
Output is correct |
35 |
Correct |
283 ms |
4224 KB |
Output is correct |
36 |
Correct |
281 ms |
4340 KB |
Output is correct |
37 |
Correct |
274 ms |
4308 KB |
Output is correct |
38 |
Correct |
275 ms |
4216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1108 KB |
Output is correct |
2 |
Correct |
6 ms |
1028 KB |
Output is correct |
3 |
Correct |
6 ms |
1108 KB |
Output is correct |
4 |
Correct |
5 ms |
1096 KB |
Output is correct |
5 |
Correct |
7 ms |
1108 KB |
Output is correct |
6 |
Correct |
6 ms |
1100 KB |
Output is correct |
7 |
Correct |
8 ms |
1096 KB |
Output is correct |
8 |
Correct |
7 ms |
1112 KB |
Output is correct |
9 |
Correct |
8 ms |
1096 KB |
Output is correct |
10 |
Correct |
9 ms |
1064 KB |
Output is correct |
11 |
Correct |
6 ms |
1108 KB |
Output is correct |
12 |
Correct |
6 ms |
1092 KB |
Output is correct |
13 |
Correct |
6 ms |
1064 KB |
Output is correct |
14 |
Correct |
6 ms |
1108 KB |
Output is correct |
15 |
Correct |
6 ms |
1064 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
5 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 |
4 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
279 ms |
4288 KB |
Output is correct |
2 |
Correct |
320 ms |
4320 KB |
Output is correct |
3 |
Correct |
295 ms |
4228 KB |
Output is correct |
4 |
Correct |
267 ms |
4220 KB |
Output is correct |
5 |
Correct |
322 ms |
4336 KB |
Output is correct |
6 |
Correct |
194 ms |
4332 KB |
Output is correct |
7 |
Correct |
202 ms |
4272 KB |
Output is correct |
8 |
Correct |
233 ms |
4268 KB |
Output is correct |
9 |
Correct |
218 ms |
4332 KB |
Output is correct |
10 |
Correct |
223 ms |
4320 KB |
Output is correct |
11 |
Correct |
223 ms |
4316 KB |
Output is correct |
12 |
Correct |
192 ms |
4292 KB |
Output is correct |
13 |
Correct |
237 ms |
4332 KB |
Output is correct |
14 |
Correct |
190 ms |
4324 KB |
Output is correct |
15 |
Correct |
194 ms |
4224 KB |
Output is correct |
16 |
Correct |
46 ms |
1032 KB |
Output is correct |
17 |
Correct |
48 ms |
1060 KB |
Output is correct |
18 |
Correct |
48 ms |
1004 KB |
Output is correct |
19 |
Correct |
50 ms |
1064 KB |
Output is correct |
20 |
Correct |
51 ms |
1080 KB |
Output is correct |
21 |
Correct |
513 ms |
3920 KB |
Output is correct |
22 |
Correct |
485 ms |
4020 KB |
Output is correct |
23 |
Correct |
468 ms |
3920 KB |
Output is correct |
24 |
Correct |
489 ms |
3808 KB |
Output is correct |
25 |
Correct |
522 ms |
3880 KB |
Output is correct |
26 |
Correct |
701 ms |
3772 KB |
Output is correct |
27 |
Correct |
749 ms |
3812 KB |
Output is correct |
28 |
Correct |
704 ms |
3756 KB |
Output is correct |
29 |
Correct |
695 ms |
3744 KB |
Output is correct |
30 |
Correct |
187 ms |
4324 KB |
Output is correct |
31 |
Correct |
181 ms |
4292 KB |
Output is correct |
32 |
Correct |
182 ms |
4200 KB |
Output is correct |
33 |
Correct |
191 ms |
4260 KB |
Output is correct |
34 |
Correct |
179 ms |
4252 KB |
Output is correct |
35 |
Correct |
283 ms |
4224 KB |
Output is correct |
36 |
Correct |
281 ms |
4340 KB |
Output is correct |
37 |
Correct |
274 ms |
4308 KB |
Output is correct |
38 |
Correct |
275 ms |
4216 KB |
Output is correct |
39 |
Correct |
6 ms |
1108 KB |
Output is correct |
40 |
Correct |
6 ms |
1028 KB |
Output is correct |
41 |
Correct |
6 ms |
1108 KB |
Output is correct |
42 |
Correct |
5 ms |
1096 KB |
Output is correct |
43 |
Correct |
7 ms |
1108 KB |
Output is correct |
44 |
Correct |
6 ms |
1100 KB |
Output is correct |
45 |
Correct |
8 ms |
1096 KB |
Output is correct |
46 |
Correct |
7 ms |
1112 KB |
Output is correct |
47 |
Correct |
8 ms |
1096 KB |
Output is correct |
48 |
Correct |
9 ms |
1064 KB |
Output is correct |
49 |
Correct |
6 ms |
1108 KB |
Output is correct |
50 |
Correct |
6 ms |
1092 KB |
Output is correct |
51 |
Correct |
6 ms |
1064 KB |
Output is correct |
52 |
Correct |
6 ms |
1108 KB |
Output is correct |
53 |
Correct |
6 ms |
1064 KB |
Output is correct |
54 |
Correct |
4 ms |
724 KB |
Output is correct |
55 |
Correct |
5 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 |
4 ms |
724 KB |
Output is correct |
59 |
Correct |
513 ms |
4332 KB |
Output is correct |
60 |
Correct |
497 ms |
4248 KB |
Output is correct |
61 |
Correct |
474 ms |
4364 KB |
Output is correct |
62 |
Correct |
494 ms |
4252 KB |
Output is correct |
63 |
Correct |
507 ms |
4236 KB |
Output is correct |
64 |
Correct |
752 ms |
4308 KB |
Output is correct |
65 |
Correct |
748 ms |
4276 KB |
Output is correct |
66 |
Correct |
736 ms |
4336 KB |
Output is correct |
67 |
Correct |
749 ms |
4336 KB |
Output is correct |
68 |
Correct |
741 ms |
4236 KB |
Output is correct |
69 |
Correct |
543 ms |
4352 KB |
Output is correct |
70 |
Correct |
563 ms |
4260 KB |
Output is correct |
71 |
Correct |
564 ms |
4280 KB |
Output is correct |
72 |
Correct |
591 ms |
4280 KB |
Output is correct |
73 |
Correct |
577 ms |
4372 KB |
Output is correct |
74 |
Correct |
90 ms |
976 KB |
Output is correct |
75 |
Correct |
91 ms |
1016 KB |
Output is correct |
76 |
Correct |
91 ms |
1056 KB |
Output is correct |
77 |
Correct |
106 ms |
1160 KB |
Output is correct |
78 |
Correct |
102 ms |
1024 KB |
Output is correct |