#include <bits/stdc++.h>
using namespace std;
const int DIM = 505;
const int MOD = 1000000007;
vector<int> lst;
pair<int, int> seg[DIM];
int dp[DIM], dp2[DIM][DIM];
int fct[DIM], inv[DIM], cmb[DIM * 2][DIM];
int logPow(int x, int n) {
if (!n) { return 1; }
int y = logPow(x, n >> 1);
if (n | 1) { y = 1LL * y * y % MOD; }
if (n & 1) { y = 1LL * y * x % MOD; }
return y; }
int main(void) {
#ifdef HOME
freopen("boat.in", "r", stdin);
freopen("boat.out", "w", stdout);
#endif
int n; cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> seg[i].first >> seg[i].second;
lst.push_back(seg[i].first); lst.push_back(++seg[i].second); }
sort(lst.begin(), lst.end());
lst.resize(unique(lst.begin(), lst.end()) - lst.begin());
fct[0] = inv[0] = 1;
for (int i = 1; i <= n; ++i) {
fct[i] = 1LL * fct[i - 1] * i % MOD;
inv[i] = logPow(fct[i], MOD - 2); }
for (int i = 1; i < lst.size(); ++i) {
int dif = lst[i] - lst[i - 1];
cmb[i][0] = 1;
for (int j = 1; j <= n; ++j) {
cmb[i][j] = 1LL * cmb[i][j - 1] * (dif - j + 1) % MOD; }
for (int j = 1; j <= n; ++j) {
cmb[i][j] = 1LL * cmb[i][j] * inv[j] % MOD; } }
for (int i = 0; i <= n; ++i) {
dp[i] = 1; }
for (int i = 1; i < lst.size(); ++i) {
int dif = lst[i] - lst[i - 1];
for (int j = 0; j <= n; ++j) {
dp2[0][j] = dp[j]; }
for (int j = 1; j <= min(dif, n); ++j) {
for (int k = j; k <= n; ++k) {
dp2[j][k] = dp2[j][k - 1];
if (seg[k].first <= lst[i - 1] and seg[k].second >= lst[i]) {
dp2[j][k] = (dp2[j][k] + dp2[j - 1][k - 1]) % MOD; }
dp[k] = (1LL * dp2[j][k] * cmb[i][j] + dp[k]) % MOD; } } }
cout << (dp[n] - 1 + MOD) % MOD;
return 0; }
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:35:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < lst.size(); ++i) {
~~^~~~~~~~~~~~
boat.cpp:44:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < lst.size(); ++i) {
~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
264 ms |
3448 KB |
Output is correct |
2 |
Correct |
278 ms |
3448 KB |
Output is correct |
3 |
Correct |
283 ms |
3452 KB |
Output is correct |
4 |
Correct |
297 ms |
3448 KB |
Output is correct |
5 |
Correct |
302 ms |
3328 KB |
Output is correct |
6 |
Correct |
201 ms |
3328 KB |
Output is correct |
7 |
Correct |
196 ms |
3400 KB |
Output is correct |
8 |
Correct |
207 ms |
3328 KB |
Output is correct |
9 |
Correct |
209 ms |
3328 KB |
Output is correct |
10 |
Correct |
206 ms |
3448 KB |
Output is correct |
11 |
Correct |
197 ms |
3448 KB |
Output is correct |
12 |
Correct |
180 ms |
3328 KB |
Output is correct |
13 |
Correct |
188 ms |
3328 KB |
Output is correct |
14 |
Correct |
190 ms |
3452 KB |
Output is correct |
15 |
Correct |
211 ms |
3448 KB |
Output is correct |
16 |
Correct |
47 ms |
1664 KB |
Output is correct |
17 |
Correct |
52 ms |
1664 KB |
Output is correct |
18 |
Correct |
51 ms |
1756 KB |
Output is correct |
19 |
Correct |
50 ms |
1664 KB |
Output is correct |
20 |
Correct |
50 ms |
1784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
264 ms |
3448 KB |
Output is correct |
2 |
Correct |
278 ms |
3448 KB |
Output is correct |
3 |
Correct |
283 ms |
3452 KB |
Output is correct |
4 |
Correct |
297 ms |
3448 KB |
Output is correct |
5 |
Correct |
302 ms |
3328 KB |
Output is correct |
6 |
Correct |
201 ms |
3328 KB |
Output is correct |
7 |
Correct |
196 ms |
3400 KB |
Output is correct |
8 |
Correct |
207 ms |
3328 KB |
Output is correct |
9 |
Correct |
209 ms |
3328 KB |
Output is correct |
10 |
Correct |
206 ms |
3448 KB |
Output is correct |
11 |
Correct |
197 ms |
3448 KB |
Output is correct |
12 |
Correct |
180 ms |
3328 KB |
Output is correct |
13 |
Correct |
188 ms |
3328 KB |
Output is correct |
14 |
Correct |
190 ms |
3452 KB |
Output is correct |
15 |
Correct |
211 ms |
3448 KB |
Output is correct |
16 |
Correct |
47 ms |
1664 KB |
Output is correct |
17 |
Correct |
52 ms |
1664 KB |
Output is correct |
18 |
Correct |
51 ms |
1756 KB |
Output is correct |
19 |
Correct |
50 ms |
1664 KB |
Output is correct |
20 |
Correct |
50 ms |
1784 KB |
Output is correct |
21 |
Correct |
20 ms |
3072 KB |
Output is correct |
22 |
Correct |
22 ms |
3200 KB |
Output is correct |
23 |
Correct |
21 ms |
3192 KB |
Output is correct |
24 |
Correct |
20 ms |
3200 KB |
Output is correct |
25 |
Correct |
20 ms |
3064 KB |
Output is correct |
26 |
Correct |
20 ms |
3072 KB |
Output is correct |
27 |
Correct |
21 ms |
3072 KB |
Output is correct |
28 |
Correct |
19 ms |
3064 KB |
Output is correct |
29 |
Correct |
25 ms |
3064 KB |
Output is correct |
30 |
Correct |
177 ms |
3328 KB |
Output is correct |
31 |
Correct |
183 ms |
3448 KB |
Output is correct |
32 |
Correct |
250 ms |
3328 KB |
Output is correct |
33 |
Correct |
195 ms |
3424 KB |
Output is correct |
34 |
Correct |
176 ms |
3452 KB |
Output is correct |
35 |
Correct |
260 ms |
3328 KB |
Output is correct |
36 |
Correct |
233 ms |
3328 KB |
Output is correct |
37 |
Correct |
252 ms |
3448 KB |
Output is correct |
38 |
Correct |
229 ms |
3456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1024 KB |
Output is correct |
2 |
Correct |
9 ms |
1028 KB |
Output is correct |
3 |
Correct |
10 ms |
1024 KB |
Output is correct |
4 |
Correct |
7 ms |
1024 KB |
Output is correct |
5 |
Correct |
8 ms |
896 KB |
Output is correct |
6 |
Correct |
10 ms |
924 KB |
Output is correct |
7 |
Correct |
9 ms |
896 KB |
Output is correct |
8 |
Correct |
8 ms |
924 KB |
Output is correct |
9 |
Correct |
8 ms |
1024 KB |
Output is correct |
10 |
Correct |
9 ms |
896 KB |
Output is correct |
11 |
Correct |
8 ms |
896 KB |
Output is correct |
12 |
Correct |
7 ms |
896 KB |
Output is correct |
13 |
Correct |
8 ms |
1024 KB |
Output is correct |
14 |
Correct |
12 ms |
1024 KB |
Output is correct |
15 |
Correct |
8 ms |
1024 KB |
Output is correct |
16 |
Correct |
6 ms |
768 KB |
Output is correct |
17 |
Correct |
6 ms |
768 KB |
Output is correct |
18 |
Correct |
7 ms |
768 KB |
Output is correct |
19 |
Correct |
7 ms |
768 KB |
Output is correct |
20 |
Correct |
5 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
264 ms |
3448 KB |
Output is correct |
2 |
Correct |
278 ms |
3448 KB |
Output is correct |
3 |
Correct |
283 ms |
3452 KB |
Output is correct |
4 |
Correct |
297 ms |
3448 KB |
Output is correct |
5 |
Correct |
302 ms |
3328 KB |
Output is correct |
6 |
Correct |
201 ms |
3328 KB |
Output is correct |
7 |
Correct |
196 ms |
3400 KB |
Output is correct |
8 |
Correct |
207 ms |
3328 KB |
Output is correct |
9 |
Correct |
209 ms |
3328 KB |
Output is correct |
10 |
Correct |
206 ms |
3448 KB |
Output is correct |
11 |
Correct |
197 ms |
3448 KB |
Output is correct |
12 |
Correct |
180 ms |
3328 KB |
Output is correct |
13 |
Correct |
188 ms |
3328 KB |
Output is correct |
14 |
Correct |
190 ms |
3452 KB |
Output is correct |
15 |
Correct |
211 ms |
3448 KB |
Output is correct |
16 |
Correct |
47 ms |
1664 KB |
Output is correct |
17 |
Correct |
52 ms |
1664 KB |
Output is correct |
18 |
Correct |
51 ms |
1756 KB |
Output is correct |
19 |
Correct |
50 ms |
1664 KB |
Output is correct |
20 |
Correct |
50 ms |
1784 KB |
Output is correct |
21 |
Correct |
20 ms |
3072 KB |
Output is correct |
22 |
Correct |
22 ms |
3200 KB |
Output is correct |
23 |
Correct |
21 ms |
3192 KB |
Output is correct |
24 |
Correct |
20 ms |
3200 KB |
Output is correct |
25 |
Correct |
20 ms |
3064 KB |
Output is correct |
26 |
Correct |
20 ms |
3072 KB |
Output is correct |
27 |
Correct |
21 ms |
3072 KB |
Output is correct |
28 |
Correct |
19 ms |
3064 KB |
Output is correct |
29 |
Correct |
25 ms |
3064 KB |
Output is correct |
30 |
Correct |
177 ms |
3328 KB |
Output is correct |
31 |
Correct |
183 ms |
3448 KB |
Output is correct |
32 |
Correct |
250 ms |
3328 KB |
Output is correct |
33 |
Correct |
195 ms |
3424 KB |
Output is correct |
34 |
Correct |
176 ms |
3452 KB |
Output is correct |
35 |
Correct |
260 ms |
3328 KB |
Output is correct |
36 |
Correct |
233 ms |
3328 KB |
Output is correct |
37 |
Correct |
252 ms |
3448 KB |
Output is correct |
38 |
Correct |
229 ms |
3456 KB |
Output is correct |
39 |
Correct |
8 ms |
1024 KB |
Output is correct |
40 |
Correct |
9 ms |
1028 KB |
Output is correct |
41 |
Correct |
10 ms |
1024 KB |
Output is correct |
42 |
Correct |
7 ms |
1024 KB |
Output is correct |
43 |
Correct |
8 ms |
896 KB |
Output is correct |
44 |
Correct |
10 ms |
924 KB |
Output is correct |
45 |
Correct |
9 ms |
896 KB |
Output is correct |
46 |
Correct |
8 ms |
924 KB |
Output is correct |
47 |
Correct |
8 ms |
1024 KB |
Output is correct |
48 |
Correct |
9 ms |
896 KB |
Output is correct |
49 |
Correct |
8 ms |
896 KB |
Output is correct |
50 |
Correct |
7 ms |
896 KB |
Output is correct |
51 |
Correct |
8 ms |
1024 KB |
Output is correct |
52 |
Correct |
12 ms |
1024 KB |
Output is correct |
53 |
Correct |
8 ms |
1024 KB |
Output is correct |
54 |
Correct |
6 ms |
768 KB |
Output is correct |
55 |
Correct |
6 ms |
768 KB |
Output is correct |
56 |
Correct |
7 ms |
768 KB |
Output is correct |
57 |
Correct |
7 ms |
768 KB |
Output is correct |
58 |
Correct |
5 ms |
768 KB |
Output is correct |
59 |
Correct |
551 ms |
3328 KB |
Output is correct |
60 |
Correct |
568 ms |
3396 KB |
Output is correct |
61 |
Correct |
567 ms |
3328 KB |
Output is correct |
62 |
Correct |
546 ms |
3372 KB |
Output is correct |
63 |
Correct |
671 ms |
3448 KB |
Output is correct |
64 |
Correct |
617 ms |
3396 KB |
Output is correct |
65 |
Correct |
629 ms |
3300 KB |
Output is correct |
66 |
Correct |
631 ms |
3304 KB |
Output is correct |
67 |
Correct |
660 ms |
3448 KB |
Output is correct |
68 |
Correct |
646 ms |
3356 KB |
Output is correct |
69 |
Correct |
505 ms |
3448 KB |
Output is correct |
70 |
Correct |
554 ms |
3448 KB |
Output is correct |
71 |
Correct |
559 ms |
3360 KB |
Output is correct |
72 |
Correct |
478 ms |
3420 KB |
Output is correct |
73 |
Correct |
559 ms |
3328 KB |
Output is correct |
74 |
Correct |
58 ms |
1664 KB |
Output is correct |
75 |
Correct |
60 ms |
1664 KB |
Output is correct |
76 |
Correct |
60 ms |
1784 KB |
Output is correct |
77 |
Correct |
60 ms |
1664 KB |
Output is correct |
78 |
Correct |
61 ms |
1784 KB |
Output is correct |