#include <bits/stdc++.h>
using namespace std;
#define getchar_unlocked getchar
#define putchar_unlocked putchar
#define ll long long
inline int in() {
int result = 0;
char ch = getchar_unlocked();
while (true) {
if(ch >= '0' && ch <= '9')
break;
ch = getchar_unlocked();
}
result = ch-'0';
while(true) {
ch = getchar_unlocked();
if (ch < '0' || ch > '9')
break;
result = result*10 + (ch - '0');
}
return result;
}
inline void out(int x) {
int rev=x, c=0;
if(!x) {
putchar_unlocked('0');
return;
}
while(!(rev%10)) {
++c;
rev/=10;
}
rev=0;
while(x) {
rev=rev*10+x%10;
x/=10;
}
while(rev) {
putchar_unlocked(rev%10+'0');
rev/=10;
}
while(c--)
putchar_unlocked('0');
}
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() {
n=in();
for(int i=0; i<n; ++i) {
a[i]=in()-1;
b[i]=in();
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;
}
}
out(dp[n][pts.size()-1]-1);
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:67:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1; i<pts.size(); ++i) {
~^~~~~~~~~~~
boat.cpp:72:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<pts.size(); ++i)
~^~~~~~~~~~~
boat.cpp:76: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 |
597 ms |
8224 KB |
Output is correct |
2 |
Correct |
551 ms |
8300 KB |
Output is correct |
3 |
Correct |
551 ms |
8440 KB |
Output is correct |
4 |
Correct |
546 ms |
8440 KB |
Output is correct |
5 |
Correct |
541 ms |
8440 KB |
Output is correct |
6 |
Correct |
282 ms |
8460 KB |
Output is correct |
7 |
Correct |
275 ms |
8464 KB |
Output is correct |
8 |
Correct |
257 ms |
8464 KB |
Output is correct |
9 |
Correct |
269 ms |
8464 KB |
Output is correct |
10 |
Correct |
259 ms |
8464 KB |
Output is correct |
11 |
Correct |
250 ms |
8464 KB |
Output is correct |
12 |
Correct |
267 ms |
8464 KB |
Output is correct |
13 |
Correct |
250 ms |
8464 KB |
Output is correct |
14 |
Correct |
241 ms |
8464 KB |
Output is correct |
15 |
Correct |
275 ms |
8464 KB |
Output is correct |
16 |
Correct |
99 ms |
8464 KB |
Output is correct |
17 |
Correct |
105 ms |
8464 KB |
Output is correct |
18 |
Correct |
115 ms |
8464 KB |
Output is correct |
19 |
Correct |
132 ms |
8464 KB |
Output is correct |
20 |
Correct |
112 ms |
8464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
597 ms |
8224 KB |
Output is correct |
2 |
Correct |
551 ms |
8300 KB |
Output is correct |
3 |
Correct |
551 ms |
8440 KB |
Output is correct |
4 |
Correct |
546 ms |
8440 KB |
Output is correct |
5 |
Correct |
541 ms |
8440 KB |
Output is correct |
6 |
Correct |
282 ms |
8460 KB |
Output is correct |
7 |
Correct |
275 ms |
8464 KB |
Output is correct |
8 |
Correct |
257 ms |
8464 KB |
Output is correct |
9 |
Correct |
269 ms |
8464 KB |
Output is correct |
10 |
Correct |
259 ms |
8464 KB |
Output is correct |
11 |
Correct |
250 ms |
8464 KB |
Output is correct |
12 |
Correct |
267 ms |
8464 KB |
Output is correct |
13 |
Correct |
250 ms |
8464 KB |
Output is correct |
14 |
Correct |
241 ms |
8464 KB |
Output is correct |
15 |
Correct |
275 ms |
8464 KB |
Output is correct |
16 |
Correct |
99 ms |
8464 KB |
Output is correct |
17 |
Correct |
105 ms |
8464 KB |
Output is correct |
18 |
Correct |
115 ms |
8464 KB |
Output is correct |
19 |
Correct |
132 ms |
8464 KB |
Output is correct |
20 |
Correct |
112 ms |
8464 KB |
Output is correct |
21 |
Correct |
504 ms |
8464 KB |
Output is correct |
22 |
Correct |
438 ms |
8464 KB |
Output is correct |
23 |
Correct |
463 ms |
8464 KB |
Output is correct |
24 |
Correct |
388 ms |
8464 KB |
Output is correct |
25 |
Correct |
396 ms |
8464 KB |
Output is correct |
26 |
Correct |
375 ms |
8464 KB |
Output is correct |
27 |
Correct |
464 ms |
8464 KB |
Output is correct |
28 |
Correct |
405 ms |
8464 KB |
Output is correct |
29 |
Correct |
411 ms |
8464 KB |
Output is correct |
30 |
Correct |
313 ms |
8492 KB |
Output is correct |
31 |
Correct |
262 ms |
8492 KB |
Output is correct |
32 |
Correct |
277 ms |
8492 KB |
Output is correct |
33 |
Correct |
264 ms |
8492 KB |
Output is correct |
34 |
Correct |
294 ms |
8492 KB |
Output is correct |
35 |
Correct |
593 ms |
8492 KB |
Output is correct |
36 |
Correct |
573 ms |
8492 KB |
Output is correct |
37 |
Correct |
561 ms |
8600 KB |
Output is correct |
38 |
Correct |
577 ms |
8600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8600 KB |
Output is correct |
2 |
Correct |
8 ms |
8600 KB |
Output is correct |
3 |
Correct |
10 ms |
8600 KB |
Output is correct |
4 |
Correct |
9 ms |
8600 KB |
Output is correct |
5 |
Correct |
9 ms |
8600 KB |
Output is correct |
6 |
Correct |
9 ms |
8600 KB |
Output is correct |
7 |
Correct |
10 ms |
8600 KB |
Output is correct |
8 |
Correct |
9 ms |
8600 KB |
Output is correct |
9 |
Correct |
10 ms |
8600 KB |
Output is correct |
10 |
Correct |
8 ms |
8600 KB |
Output is correct |
11 |
Correct |
9 ms |
8600 KB |
Output is correct |
12 |
Correct |
10 ms |
8600 KB |
Output is correct |
13 |
Correct |
8 ms |
8600 KB |
Output is correct |
14 |
Correct |
8 ms |
8600 KB |
Output is correct |
15 |
Correct |
9 ms |
8600 KB |
Output is correct |
16 |
Correct |
6 ms |
8600 KB |
Output is correct |
17 |
Correct |
6 ms |
8600 KB |
Output is correct |
18 |
Correct |
7 ms |
8600 KB |
Output is correct |
19 |
Correct |
6 ms |
8600 KB |
Output is correct |
20 |
Correct |
6 ms |
8600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
597 ms |
8224 KB |
Output is correct |
2 |
Correct |
551 ms |
8300 KB |
Output is correct |
3 |
Correct |
551 ms |
8440 KB |
Output is correct |
4 |
Correct |
546 ms |
8440 KB |
Output is correct |
5 |
Correct |
541 ms |
8440 KB |
Output is correct |
6 |
Correct |
282 ms |
8460 KB |
Output is correct |
7 |
Correct |
275 ms |
8464 KB |
Output is correct |
8 |
Correct |
257 ms |
8464 KB |
Output is correct |
9 |
Correct |
269 ms |
8464 KB |
Output is correct |
10 |
Correct |
259 ms |
8464 KB |
Output is correct |
11 |
Correct |
250 ms |
8464 KB |
Output is correct |
12 |
Correct |
267 ms |
8464 KB |
Output is correct |
13 |
Correct |
250 ms |
8464 KB |
Output is correct |
14 |
Correct |
241 ms |
8464 KB |
Output is correct |
15 |
Correct |
275 ms |
8464 KB |
Output is correct |
16 |
Correct |
99 ms |
8464 KB |
Output is correct |
17 |
Correct |
105 ms |
8464 KB |
Output is correct |
18 |
Correct |
115 ms |
8464 KB |
Output is correct |
19 |
Correct |
132 ms |
8464 KB |
Output is correct |
20 |
Correct |
112 ms |
8464 KB |
Output is correct |
21 |
Correct |
504 ms |
8464 KB |
Output is correct |
22 |
Correct |
438 ms |
8464 KB |
Output is correct |
23 |
Correct |
463 ms |
8464 KB |
Output is correct |
24 |
Correct |
388 ms |
8464 KB |
Output is correct |
25 |
Correct |
396 ms |
8464 KB |
Output is correct |
26 |
Correct |
375 ms |
8464 KB |
Output is correct |
27 |
Correct |
464 ms |
8464 KB |
Output is correct |
28 |
Correct |
405 ms |
8464 KB |
Output is correct |
29 |
Correct |
411 ms |
8464 KB |
Output is correct |
30 |
Correct |
313 ms |
8492 KB |
Output is correct |
31 |
Correct |
262 ms |
8492 KB |
Output is correct |
32 |
Correct |
277 ms |
8492 KB |
Output is correct |
33 |
Correct |
264 ms |
8492 KB |
Output is correct |
34 |
Correct |
294 ms |
8492 KB |
Output is correct |
35 |
Correct |
593 ms |
8492 KB |
Output is correct |
36 |
Correct |
573 ms |
8492 KB |
Output is correct |
37 |
Correct |
561 ms |
8600 KB |
Output is correct |
38 |
Correct |
577 ms |
8600 KB |
Output is correct |
39 |
Correct |
10 ms |
8600 KB |
Output is correct |
40 |
Correct |
8 ms |
8600 KB |
Output is correct |
41 |
Correct |
10 ms |
8600 KB |
Output is correct |
42 |
Correct |
9 ms |
8600 KB |
Output is correct |
43 |
Correct |
9 ms |
8600 KB |
Output is correct |
44 |
Correct |
9 ms |
8600 KB |
Output is correct |
45 |
Correct |
10 ms |
8600 KB |
Output is correct |
46 |
Correct |
9 ms |
8600 KB |
Output is correct |
47 |
Correct |
10 ms |
8600 KB |
Output is correct |
48 |
Correct |
8 ms |
8600 KB |
Output is correct |
49 |
Correct |
9 ms |
8600 KB |
Output is correct |
50 |
Correct |
10 ms |
8600 KB |
Output is correct |
51 |
Correct |
8 ms |
8600 KB |
Output is correct |
52 |
Correct |
8 ms |
8600 KB |
Output is correct |
53 |
Correct |
9 ms |
8600 KB |
Output is correct |
54 |
Correct |
6 ms |
8600 KB |
Output is correct |
55 |
Correct |
6 ms |
8600 KB |
Output is correct |
56 |
Correct |
7 ms |
8600 KB |
Output is correct |
57 |
Correct |
6 ms |
8600 KB |
Output is correct |
58 |
Correct |
6 ms |
8600 KB |
Output is correct |
59 |
Correct |
441 ms |
8600 KB |
Output is correct |
60 |
Correct |
482 ms |
8600 KB |
Output is correct |
61 |
Correct |
521 ms |
8600 KB |
Output is correct |
62 |
Correct |
470 ms |
8600 KB |
Output is correct |
63 |
Correct |
498 ms |
8600 KB |
Output is correct |
64 |
Correct |
474 ms |
8600 KB |
Output is correct |
65 |
Correct |
448 ms |
8600 KB |
Output is correct |
66 |
Correct |
491 ms |
8600 KB |
Output is correct |
67 |
Correct |
563 ms |
8600 KB |
Output is correct |
68 |
Correct |
493 ms |
8600 KB |
Output is correct |
69 |
Correct |
450 ms |
8600 KB |
Output is correct |
70 |
Correct |
426 ms |
8600 KB |
Output is correct |
71 |
Correct |
431 ms |
8600 KB |
Output is correct |
72 |
Correct |
574 ms |
8628 KB |
Output is correct |
73 |
Correct |
436 ms |
8628 KB |
Output is correct |
74 |
Correct |
103 ms |
8628 KB |
Output is correct |
75 |
Correct |
111 ms |
8628 KB |
Output is correct |
76 |
Correct |
103 ms |
8628 KB |
Output is correct |
77 |
Correct |
114 ms |
8628 KB |
Output is correct |
78 |
Correct |
103 ms |
8628 KB |
Output is correct |