#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxN=500, M=1e9+7;
int n, a[mxN], b[mxN];
ll dp[mxN+1][2*mxN], c[2*mxN][mxN+1];
vector<int> pts;
inline ll modI(ll a, ll m) {
return a<=1?a:(1-modI(m%a, a)*m)/a+m;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i=0; i<n; ++i) {
cin >> a[i] >> b[i], --a[i];
pts.push_back(a[i]);
pts.push_back(b[i]);
}
sort(pts.begin(), pts.end());
pts.resize(unique(pts.begin(), pts.end())-pts.begin());
for(int i=1; i<pts.size(); ++i) {
c[i][1]=pts[i]-pts[i-1];
for(int j=2; j<=n; ++j)
c[i][j]=c[i][j-1]*(pts[i]-pts[i-1]+j-1)%M*modI(j, M)%M;
}
for(int i=0; i<pts.size(); ++i)
dp[0][i]=1;
for(int i=1; i<=n; ++i) {
dp[i][0]=1;
for(int j=1; j<pts.size(); ++j) {
dp[i][j]=dp[i][j-1];
for(int k=i, n2=0; k; --k) {
if(pts[j]>a[k-1]&&pts[j]<=b[k-1]) {
++n2;
dp[i][j]+=dp[k-1][j-1]*c[j][n2]%M;
}
}
dp[i][j]%=M;
}
}
cout << dp[n][pts.size()-1]-1;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:27:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1; i<pts.size(); ++i) {
~^~~~~~~~~~~
boat.cpp:32:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<pts.size(); ++i)
~^~~~~~~~~~~
boat.cpp:36:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=1; j<pts.size(); ++j) {
~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
496 ms |
8184 KB |
Output is correct |
2 |
Correct |
515 ms |
8424 KB |
Output is correct |
3 |
Correct |
520 ms |
8424 KB |
Output is correct |
4 |
Correct |
525 ms |
8424 KB |
Output is correct |
5 |
Correct |
506 ms |
8544 KB |
Output is correct |
6 |
Correct |
261 ms |
8544 KB |
Output is correct |
7 |
Correct |
252 ms |
8544 KB |
Output is correct |
8 |
Correct |
262 ms |
8544 KB |
Output is correct |
9 |
Correct |
268 ms |
8560 KB |
Output is correct |
10 |
Correct |
254 ms |
8560 KB |
Output is correct |
11 |
Correct |
260 ms |
8560 KB |
Output is correct |
12 |
Correct |
266 ms |
8560 KB |
Output is correct |
13 |
Correct |
252 ms |
8560 KB |
Output is correct |
14 |
Correct |
241 ms |
8560 KB |
Output is correct |
15 |
Correct |
261 ms |
8560 KB |
Output is correct |
16 |
Correct |
98 ms |
8560 KB |
Output is correct |
17 |
Correct |
98 ms |
8560 KB |
Output is correct |
18 |
Correct |
99 ms |
8560 KB |
Output is correct |
19 |
Correct |
100 ms |
8560 KB |
Output is correct |
20 |
Correct |
96 ms |
8560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
496 ms |
8184 KB |
Output is correct |
2 |
Correct |
515 ms |
8424 KB |
Output is correct |
3 |
Correct |
520 ms |
8424 KB |
Output is correct |
4 |
Correct |
525 ms |
8424 KB |
Output is correct |
5 |
Correct |
506 ms |
8544 KB |
Output is correct |
6 |
Correct |
261 ms |
8544 KB |
Output is correct |
7 |
Correct |
252 ms |
8544 KB |
Output is correct |
8 |
Correct |
262 ms |
8544 KB |
Output is correct |
9 |
Correct |
268 ms |
8560 KB |
Output is correct |
10 |
Correct |
254 ms |
8560 KB |
Output is correct |
11 |
Correct |
260 ms |
8560 KB |
Output is correct |
12 |
Correct |
266 ms |
8560 KB |
Output is correct |
13 |
Correct |
252 ms |
8560 KB |
Output is correct |
14 |
Correct |
241 ms |
8560 KB |
Output is correct |
15 |
Correct |
261 ms |
8560 KB |
Output is correct |
16 |
Correct |
98 ms |
8560 KB |
Output is correct |
17 |
Correct |
98 ms |
8560 KB |
Output is correct |
18 |
Correct |
99 ms |
8560 KB |
Output is correct |
19 |
Correct |
100 ms |
8560 KB |
Output is correct |
20 |
Correct |
96 ms |
8560 KB |
Output is correct |
21 |
Correct |
407 ms |
8560 KB |
Output is correct |
22 |
Correct |
414 ms |
8560 KB |
Output is correct |
23 |
Correct |
383 ms |
8560 KB |
Output is correct |
24 |
Correct |
388 ms |
8560 KB |
Output is correct |
25 |
Correct |
396 ms |
8560 KB |
Output is correct |
26 |
Correct |
393 ms |
8560 KB |
Output is correct |
27 |
Correct |
420 ms |
8560 KB |
Output is correct |
28 |
Correct |
398 ms |
8560 KB |
Output is correct |
29 |
Correct |
388 ms |
8560 KB |
Output is correct |
30 |
Correct |
272 ms |
8560 KB |
Output is correct |
31 |
Correct |
248 ms |
8560 KB |
Output is correct |
32 |
Correct |
284 ms |
8576 KB |
Output is correct |
33 |
Correct |
254 ms |
8576 KB |
Output is correct |
34 |
Correct |
248 ms |
8576 KB |
Output is correct |
35 |
Correct |
500 ms |
8648 KB |
Output is correct |
36 |
Correct |
497 ms |
8648 KB |
Output is correct |
37 |
Correct |
538 ms |
8648 KB |
Output is correct |
38 |
Correct |
517 ms |
8648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8648 KB |
Output is correct |
2 |
Correct |
10 ms |
8648 KB |
Output is correct |
3 |
Correct |
8 ms |
8648 KB |
Output is correct |
4 |
Correct |
9 ms |
8648 KB |
Output is correct |
5 |
Correct |
9 ms |
8648 KB |
Output is correct |
6 |
Correct |
10 ms |
8648 KB |
Output is correct |
7 |
Correct |
9 ms |
8648 KB |
Output is correct |
8 |
Correct |
9 ms |
8648 KB |
Output is correct |
9 |
Correct |
9 ms |
8648 KB |
Output is correct |
10 |
Correct |
9 ms |
8648 KB |
Output is correct |
11 |
Correct |
8 ms |
8648 KB |
Output is correct |
12 |
Correct |
8 ms |
8648 KB |
Output is correct |
13 |
Correct |
9 ms |
8648 KB |
Output is correct |
14 |
Correct |
9 ms |
8648 KB |
Output is correct |
15 |
Correct |
8 ms |
8648 KB |
Output is correct |
16 |
Correct |
6 ms |
8648 KB |
Output is correct |
17 |
Correct |
6 ms |
8648 KB |
Output is correct |
18 |
Correct |
6 ms |
8648 KB |
Output is correct |
19 |
Correct |
6 ms |
8648 KB |
Output is correct |
20 |
Correct |
6 ms |
8648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
496 ms |
8184 KB |
Output is correct |
2 |
Correct |
515 ms |
8424 KB |
Output is correct |
3 |
Correct |
520 ms |
8424 KB |
Output is correct |
4 |
Correct |
525 ms |
8424 KB |
Output is correct |
5 |
Correct |
506 ms |
8544 KB |
Output is correct |
6 |
Correct |
261 ms |
8544 KB |
Output is correct |
7 |
Correct |
252 ms |
8544 KB |
Output is correct |
8 |
Correct |
262 ms |
8544 KB |
Output is correct |
9 |
Correct |
268 ms |
8560 KB |
Output is correct |
10 |
Correct |
254 ms |
8560 KB |
Output is correct |
11 |
Correct |
260 ms |
8560 KB |
Output is correct |
12 |
Correct |
266 ms |
8560 KB |
Output is correct |
13 |
Correct |
252 ms |
8560 KB |
Output is correct |
14 |
Correct |
241 ms |
8560 KB |
Output is correct |
15 |
Correct |
261 ms |
8560 KB |
Output is correct |
16 |
Correct |
98 ms |
8560 KB |
Output is correct |
17 |
Correct |
98 ms |
8560 KB |
Output is correct |
18 |
Correct |
99 ms |
8560 KB |
Output is correct |
19 |
Correct |
100 ms |
8560 KB |
Output is correct |
20 |
Correct |
96 ms |
8560 KB |
Output is correct |
21 |
Correct |
407 ms |
8560 KB |
Output is correct |
22 |
Correct |
414 ms |
8560 KB |
Output is correct |
23 |
Correct |
383 ms |
8560 KB |
Output is correct |
24 |
Correct |
388 ms |
8560 KB |
Output is correct |
25 |
Correct |
396 ms |
8560 KB |
Output is correct |
26 |
Correct |
393 ms |
8560 KB |
Output is correct |
27 |
Correct |
420 ms |
8560 KB |
Output is correct |
28 |
Correct |
398 ms |
8560 KB |
Output is correct |
29 |
Correct |
388 ms |
8560 KB |
Output is correct |
30 |
Correct |
272 ms |
8560 KB |
Output is correct |
31 |
Correct |
248 ms |
8560 KB |
Output is correct |
32 |
Correct |
284 ms |
8576 KB |
Output is correct |
33 |
Correct |
254 ms |
8576 KB |
Output is correct |
34 |
Correct |
248 ms |
8576 KB |
Output is correct |
35 |
Correct |
500 ms |
8648 KB |
Output is correct |
36 |
Correct |
497 ms |
8648 KB |
Output is correct |
37 |
Correct |
538 ms |
8648 KB |
Output is correct |
38 |
Correct |
517 ms |
8648 KB |
Output is correct |
39 |
Correct |
10 ms |
8648 KB |
Output is correct |
40 |
Correct |
10 ms |
8648 KB |
Output is correct |
41 |
Correct |
8 ms |
8648 KB |
Output is correct |
42 |
Correct |
9 ms |
8648 KB |
Output is correct |
43 |
Correct |
9 ms |
8648 KB |
Output is correct |
44 |
Correct |
10 ms |
8648 KB |
Output is correct |
45 |
Correct |
9 ms |
8648 KB |
Output is correct |
46 |
Correct |
9 ms |
8648 KB |
Output is correct |
47 |
Correct |
9 ms |
8648 KB |
Output is correct |
48 |
Correct |
9 ms |
8648 KB |
Output is correct |
49 |
Correct |
8 ms |
8648 KB |
Output is correct |
50 |
Correct |
8 ms |
8648 KB |
Output is correct |
51 |
Correct |
9 ms |
8648 KB |
Output is correct |
52 |
Correct |
9 ms |
8648 KB |
Output is correct |
53 |
Correct |
8 ms |
8648 KB |
Output is correct |
54 |
Correct |
6 ms |
8648 KB |
Output is correct |
55 |
Correct |
6 ms |
8648 KB |
Output is correct |
56 |
Correct |
6 ms |
8648 KB |
Output is correct |
57 |
Correct |
6 ms |
8648 KB |
Output is correct |
58 |
Correct |
6 ms |
8648 KB |
Output is correct |
59 |
Correct |
439 ms |
8656 KB |
Output is correct |
60 |
Correct |
505 ms |
8656 KB |
Output is correct |
61 |
Correct |
411 ms |
8656 KB |
Output is correct |
62 |
Correct |
456 ms |
8656 KB |
Output is correct |
63 |
Correct |
418 ms |
8656 KB |
Output is correct |
64 |
Correct |
444 ms |
8656 KB |
Output is correct |
65 |
Correct |
557 ms |
8656 KB |
Output is correct |
66 |
Correct |
458 ms |
8656 KB |
Output is correct |
67 |
Correct |
477 ms |
8656 KB |
Output is correct |
68 |
Correct |
448 ms |
8656 KB |
Output is correct |
69 |
Correct |
531 ms |
8656 KB |
Output is correct |
70 |
Correct |
437 ms |
8656 KB |
Output is correct |
71 |
Correct |
452 ms |
8656 KB |
Output is correct |
72 |
Correct |
429 ms |
8656 KB |
Output is correct |
73 |
Correct |
484 ms |
8656 KB |
Output is correct |
74 |
Correct |
102 ms |
8656 KB |
Output is correct |
75 |
Correct |
115 ms |
8656 KB |
Output is correct |
76 |
Correct |
157 ms |
8656 KB |
Output is correct |
77 |
Correct |
115 ms |
8656 KB |
Output is correct |
78 |
Correct |
119 ms |
8656 KB |
Output is correct |