#include <bits/stdc++.h>
using namespace std;
#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:65:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1; i<pts.size(); ++i) {
~^~~~~~~~~~~
boat.cpp:70:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<pts.size(); ++i)
~^~~~~~~~~~~
boat.cpp:74:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=1; j<pts.size(); ++j) {
~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
547 ms |
8188 KB |
Output is correct |
2 |
Correct |
592 ms |
8292 KB |
Output is correct |
3 |
Correct |
559 ms |
8488 KB |
Output is correct |
4 |
Correct |
555 ms |
8488 KB |
Output is correct |
5 |
Correct |
550 ms |
8488 KB |
Output is correct |
6 |
Correct |
253 ms |
8488 KB |
Output is correct |
7 |
Correct |
247 ms |
8488 KB |
Output is correct |
8 |
Correct |
255 ms |
8488 KB |
Output is correct |
9 |
Correct |
263 ms |
8488 KB |
Output is correct |
10 |
Correct |
252 ms |
8488 KB |
Output is correct |
11 |
Correct |
254 ms |
8528 KB |
Output is correct |
12 |
Correct |
263 ms |
8544 KB |
Output is correct |
13 |
Correct |
268 ms |
8544 KB |
Output is correct |
14 |
Correct |
252 ms |
8544 KB |
Output is correct |
15 |
Correct |
264 ms |
8544 KB |
Output is correct |
16 |
Correct |
98 ms |
8544 KB |
Output is correct |
17 |
Correct |
106 ms |
8544 KB |
Output is correct |
18 |
Correct |
103 ms |
8544 KB |
Output is correct |
19 |
Correct |
113 ms |
8544 KB |
Output is correct |
20 |
Correct |
102 ms |
8544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
547 ms |
8188 KB |
Output is correct |
2 |
Correct |
592 ms |
8292 KB |
Output is correct |
3 |
Correct |
559 ms |
8488 KB |
Output is correct |
4 |
Correct |
555 ms |
8488 KB |
Output is correct |
5 |
Correct |
550 ms |
8488 KB |
Output is correct |
6 |
Correct |
253 ms |
8488 KB |
Output is correct |
7 |
Correct |
247 ms |
8488 KB |
Output is correct |
8 |
Correct |
255 ms |
8488 KB |
Output is correct |
9 |
Correct |
263 ms |
8488 KB |
Output is correct |
10 |
Correct |
252 ms |
8488 KB |
Output is correct |
11 |
Correct |
254 ms |
8528 KB |
Output is correct |
12 |
Correct |
263 ms |
8544 KB |
Output is correct |
13 |
Correct |
268 ms |
8544 KB |
Output is correct |
14 |
Correct |
252 ms |
8544 KB |
Output is correct |
15 |
Correct |
264 ms |
8544 KB |
Output is correct |
16 |
Correct |
98 ms |
8544 KB |
Output is correct |
17 |
Correct |
106 ms |
8544 KB |
Output is correct |
18 |
Correct |
103 ms |
8544 KB |
Output is correct |
19 |
Correct |
113 ms |
8544 KB |
Output is correct |
20 |
Correct |
102 ms |
8544 KB |
Output is correct |
21 |
Correct |
414 ms |
8544 KB |
Output is correct |
22 |
Correct |
393 ms |
8544 KB |
Output is correct |
23 |
Correct |
446 ms |
8544 KB |
Output is correct |
24 |
Correct |
416 ms |
8544 KB |
Output is correct |
25 |
Correct |
483 ms |
8544 KB |
Output is correct |
26 |
Correct |
545 ms |
8544 KB |
Output is correct |
27 |
Correct |
556 ms |
8544 KB |
Output is correct |
28 |
Correct |
456 ms |
8544 KB |
Output is correct |
29 |
Correct |
522 ms |
8544 KB |
Output is correct |
30 |
Correct |
275 ms |
8544 KB |
Output is correct |
31 |
Correct |
292 ms |
8544 KB |
Output is correct |
32 |
Correct |
287 ms |
8544 KB |
Output is correct |
33 |
Correct |
285 ms |
8544 KB |
Output is correct |
34 |
Correct |
266 ms |
8552 KB |
Output is correct |
35 |
Correct |
578 ms |
8552 KB |
Output is correct |
36 |
Correct |
576 ms |
8552 KB |
Output is correct |
37 |
Correct |
597 ms |
8552 KB |
Output is correct |
38 |
Correct |
575 ms |
8552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8552 KB |
Output is correct |
2 |
Correct |
8 ms |
8552 KB |
Output is correct |
3 |
Correct |
9 ms |
8552 KB |
Output is correct |
4 |
Correct |
11 ms |
8552 KB |
Output is correct |
5 |
Correct |
9 ms |
8552 KB |
Output is correct |
6 |
Correct |
11 ms |
8552 KB |
Output is correct |
7 |
Correct |
9 ms |
8552 KB |
Output is correct |
8 |
Correct |
12 ms |
8552 KB |
Output is correct |
9 |
Correct |
9 ms |
8552 KB |
Output is correct |
10 |
Correct |
9 ms |
8552 KB |
Output is correct |
11 |
Correct |
9 ms |
8552 KB |
Output is correct |
12 |
Correct |
9 ms |
8552 KB |
Output is correct |
13 |
Correct |
9 ms |
8552 KB |
Output is correct |
14 |
Correct |
8 ms |
8552 KB |
Output is correct |
15 |
Correct |
9 ms |
8552 KB |
Output is correct |
16 |
Correct |
7 ms |
8552 KB |
Output is correct |
17 |
Correct |
6 ms |
8552 KB |
Output is correct |
18 |
Correct |
6 ms |
8552 KB |
Output is correct |
19 |
Correct |
6 ms |
8552 KB |
Output is correct |
20 |
Correct |
6 ms |
8552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
547 ms |
8188 KB |
Output is correct |
2 |
Correct |
592 ms |
8292 KB |
Output is correct |
3 |
Correct |
559 ms |
8488 KB |
Output is correct |
4 |
Correct |
555 ms |
8488 KB |
Output is correct |
5 |
Correct |
550 ms |
8488 KB |
Output is correct |
6 |
Correct |
253 ms |
8488 KB |
Output is correct |
7 |
Correct |
247 ms |
8488 KB |
Output is correct |
8 |
Correct |
255 ms |
8488 KB |
Output is correct |
9 |
Correct |
263 ms |
8488 KB |
Output is correct |
10 |
Correct |
252 ms |
8488 KB |
Output is correct |
11 |
Correct |
254 ms |
8528 KB |
Output is correct |
12 |
Correct |
263 ms |
8544 KB |
Output is correct |
13 |
Correct |
268 ms |
8544 KB |
Output is correct |
14 |
Correct |
252 ms |
8544 KB |
Output is correct |
15 |
Correct |
264 ms |
8544 KB |
Output is correct |
16 |
Correct |
98 ms |
8544 KB |
Output is correct |
17 |
Correct |
106 ms |
8544 KB |
Output is correct |
18 |
Correct |
103 ms |
8544 KB |
Output is correct |
19 |
Correct |
113 ms |
8544 KB |
Output is correct |
20 |
Correct |
102 ms |
8544 KB |
Output is correct |
21 |
Correct |
414 ms |
8544 KB |
Output is correct |
22 |
Correct |
393 ms |
8544 KB |
Output is correct |
23 |
Correct |
446 ms |
8544 KB |
Output is correct |
24 |
Correct |
416 ms |
8544 KB |
Output is correct |
25 |
Correct |
483 ms |
8544 KB |
Output is correct |
26 |
Correct |
545 ms |
8544 KB |
Output is correct |
27 |
Correct |
556 ms |
8544 KB |
Output is correct |
28 |
Correct |
456 ms |
8544 KB |
Output is correct |
29 |
Correct |
522 ms |
8544 KB |
Output is correct |
30 |
Correct |
275 ms |
8544 KB |
Output is correct |
31 |
Correct |
292 ms |
8544 KB |
Output is correct |
32 |
Correct |
287 ms |
8544 KB |
Output is correct |
33 |
Correct |
285 ms |
8544 KB |
Output is correct |
34 |
Correct |
266 ms |
8552 KB |
Output is correct |
35 |
Correct |
578 ms |
8552 KB |
Output is correct |
36 |
Correct |
576 ms |
8552 KB |
Output is correct |
37 |
Correct |
597 ms |
8552 KB |
Output is correct |
38 |
Correct |
575 ms |
8552 KB |
Output is correct |
39 |
Correct |
8 ms |
8552 KB |
Output is correct |
40 |
Correct |
8 ms |
8552 KB |
Output is correct |
41 |
Correct |
9 ms |
8552 KB |
Output is correct |
42 |
Correct |
11 ms |
8552 KB |
Output is correct |
43 |
Correct |
9 ms |
8552 KB |
Output is correct |
44 |
Correct |
11 ms |
8552 KB |
Output is correct |
45 |
Correct |
9 ms |
8552 KB |
Output is correct |
46 |
Correct |
12 ms |
8552 KB |
Output is correct |
47 |
Correct |
9 ms |
8552 KB |
Output is correct |
48 |
Correct |
9 ms |
8552 KB |
Output is correct |
49 |
Correct |
9 ms |
8552 KB |
Output is correct |
50 |
Correct |
9 ms |
8552 KB |
Output is correct |
51 |
Correct |
9 ms |
8552 KB |
Output is correct |
52 |
Correct |
8 ms |
8552 KB |
Output is correct |
53 |
Correct |
9 ms |
8552 KB |
Output is correct |
54 |
Correct |
7 ms |
8552 KB |
Output is correct |
55 |
Correct |
6 ms |
8552 KB |
Output is correct |
56 |
Correct |
6 ms |
8552 KB |
Output is correct |
57 |
Correct |
6 ms |
8552 KB |
Output is correct |
58 |
Correct |
6 ms |
8552 KB |
Output is correct |
59 |
Correct |
444 ms |
8552 KB |
Output is correct |
60 |
Correct |
502 ms |
8560 KB |
Output is correct |
61 |
Correct |
482 ms |
8560 KB |
Output is correct |
62 |
Correct |
434 ms |
8560 KB |
Output is correct |
63 |
Correct |
428 ms |
8560 KB |
Output is correct |
64 |
Correct |
537 ms |
8560 KB |
Output is correct |
65 |
Correct |
454 ms |
8560 KB |
Output is correct |
66 |
Correct |
449 ms |
8560 KB |
Output is correct |
67 |
Correct |
474 ms |
8560 KB |
Output is correct |
68 |
Correct |
623 ms |
8560 KB |
Output is correct |
69 |
Correct |
430 ms |
8560 KB |
Output is correct |
70 |
Correct |
451 ms |
8676 KB |
Output is correct |
71 |
Correct |
438 ms |
8676 KB |
Output is correct |
72 |
Correct |
441 ms |
8676 KB |
Output is correct |
73 |
Correct |
492 ms |
8676 KB |
Output is correct |
74 |
Correct |
100 ms |
8676 KB |
Output is correct |
75 |
Correct |
101 ms |
8676 KB |
Output is correct |
76 |
Correct |
102 ms |
8676 KB |
Output is correct |
77 |
Correct |
101 ms |
8676 KB |
Output is correct |
78 |
Correct |
108 ms |
8676 KB |
Output is correct |