#include<bits/stdc++.h>
using namespace std;
#define N 505
long long dp[N][2*N],a[N],b[N],len[2*N],inv[N],cnt,ch,mod=1e9+7;
vector<long long> v;
int main(){
int n,i,j,k;
scanf("%d",&n);
inv[1]=1;
for(i=2;i<N;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
for(i=1;i<=n;i++)scanf("%lld %lld",&a[i],&b[i]),v.push_back(a[i]),v.push_back(b[i]+1);
sort(v.begin(),v.end());
v.resize(unique(v.begin(),v.end())-v.begin());
for(i=1;i<=n;i++){
a[i]=upper_bound(v.begin(),v.end(),a[i])-v.begin();
b[i]=upper_bound(v.begin(),v.end(),b[i])-v.begin();
}
for(i=1;i<v.size();i++)len[i]=v[i]-v[i-1];
for(i=0;i<v.size();i++)dp[0][i]=1;
for(i=1;i<=n;i++){
for(j=a[i];j<=b[i];j++){
dp[i][j]=len[j]*dp[i-1][j-1]%mod;
cnt=1,ch=len[j]-1;
for(k=i-1;k>0;k--){
if(a[k]<=j&&j<=b[k]){
cnt++;
ch=ch*(len[j]+cnt-2)%mod*inv[cnt]%mod;
if(!ch)break;
dp[i][j]=(dp[i][j]+dp[k-1][j-1]*ch)%mod;
}
}
}
dp[i][0]=1;
for(j=1;j<v.size();j++)
dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+mod)%mod;
}
printf("%lld",(dp[n][v.size()-1]-1+mod)%mod);
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:20:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(i=1;i<v.size();i++)len[i]=v[i]-v[i-1];
| ~^~~~~~~~~
boat.cpp:21:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(i=0;i<v.size();i++)dp[0][i]=1;
| ~^~~~~~~~~
boat.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(j=1;j<v.size();j++)
| ~^~~~~~~~~
boat.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
boat.cpp:13:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | for(i=1;i<=n;i++)scanf("%lld %lld",&a[i],&b[i]),v.push_back(a[i]),v.push_back(b[i]+1);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4180 KB |
Output is correct |
2 |
Correct |
6 ms |
4268 KB |
Output is correct |
3 |
Correct |
6 ms |
4180 KB |
Output is correct |
4 |
Correct |
6 ms |
4180 KB |
Output is correct |
5 |
Correct |
5 ms |
4180 KB |
Output is correct |
6 |
Correct |
5 ms |
4180 KB |
Output is correct |
7 |
Correct |
6 ms |
4180 KB |
Output is correct |
8 |
Correct |
6 ms |
4180 KB |
Output is correct |
9 |
Correct |
5 ms |
4180 KB |
Output is correct |
10 |
Correct |
5 ms |
4180 KB |
Output is correct |
11 |
Correct |
6 ms |
4220 KB |
Output is correct |
12 |
Correct |
6 ms |
4180 KB |
Output is correct |
13 |
Correct |
6 ms |
4180 KB |
Output is correct |
14 |
Correct |
6 ms |
4228 KB |
Output is correct |
15 |
Correct |
5 ms |
4180 KB |
Output is correct |
16 |
Correct |
2 ms |
3028 KB |
Output is correct |
17 |
Correct |
3 ms |
3028 KB |
Output is correct |
18 |
Correct |
2 ms |
3028 KB |
Output is correct |
19 |
Correct |
2 ms |
3028 KB |
Output is correct |
20 |
Correct |
2 ms |
3028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4180 KB |
Output is correct |
2 |
Correct |
6 ms |
4268 KB |
Output is correct |
3 |
Correct |
6 ms |
4180 KB |
Output is correct |
4 |
Correct |
6 ms |
4180 KB |
Output is correct |
5 |
Correct |
5 ms |
4180 KB |
Output is correct |
6 |
Correct |
5 ms |
4180 KB |
Output is correct |
7 |
Correct |
6 ms |
4180 KB |
Output is correct |
8 |
Correct |
6 ms |
4180 KB |
Output is correct |
9 |
Correct |
5 ms |
4180 KB |
Output is correct |
10 |
Correct |
5 ms |
4180 KB |
Output is correct |
11 |
Correct |
6 ms |
4220 KB |
Output is correct |
12 |
Correct |
6 ms |
4180 KB |
Output is correct |
13 |
Correct |
6 ms |
4180 KB |
Output is correct |
14 |
Correct |
6 ms |
4228 KB |
Output is correct |
15 |
Correct |
5 ms |
4180 KB |
Output is correct |
16 |
Correct |
2 ms |
3028 KB |
Output is correct |
17 |
Correct |
3 ms |
3028 KB |
Output is correct |
18 |
Correct |
2 ms |
3028 KB |
Output is correct |
19 |
Correct |
2 ms |
3028 KB |
Output is correct |
20 |
Correct |
2 ms |
3028 KB |
Output is correct |
21 |
Correct |
283 ms |
4256 KB |
Output is correct |
22 |
Correct |
270 ms |
4172 KB |
Output is correct |
23 |
Correct |
233 ms |
4232 KB |
Output is correct |
24 |
Correct |
283 ms |
4180 KB |
Output is correct |
25 |
Correct |
277 ms |
4172 KB |
Output is correct |
26 |
Correct |
582 ms |
4340 KB |
Output is correct |
27 |
Correct |
590 ms |
4220 KB |
Output is correct |
28 |
Correct |
623 ms |
4172 KB |
Output is correct |
29 |
Correct |
622 ms |
4424 KB |
Output is correct |
30 |
Correct |
7 ms |
4284 KB |
Output is correct |
31 |
Correct |
7 ms |
4284 KB |
Output is correct |
32 |
Correct |
6 ms |
4180 KB |
Output is correct |
33 |
Correct |
7 ms |
4280 KB |
Output is correct |
34 |
Correct |
6 ms |
4288 KB |
Output is correct |
35 |
Correct |
6 ms |
4180 KB |
Output is correct |
36 |
Correct |
6 ms |
4296 KB |
Output is correct |
37 |
Correct |
6 ms |
4308 KB |
Output is correct |
38 |
Correct |
6 ms |
4308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
812 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
4 ms |
852 KB |
Output is correct |
4 |
Correct |
5 ms |
852 KB |
Output is correct |
5 |
Correct |
5 ms |
852 KB |
Output is correct |
6 |
Correct |
11 ms |
828 KB |
Output is correct |
7 |
Correct |
11 ms |
852 KB |
Output is correct |
8 |
Correct |
11 ms |
852 KB |
Output is correct |
9 |
Correct |
10 ms |
864 KB |
Output is correct |
10 |
Correct |
10 ms |
852 KB |
Output is correct |
11 |
Correct |
5 ms |
852 KB |
Output is correct |
12 |
Correct |
4 ms |
852 KB |
Output is correct |
13 |
Correct |
4 ms |
852 KB |
Output is correct |
14 |
Correct |
5 ms |
852 KB |
Output is correct |
15 |
Correct |
5 ms |
852 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
820 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 |
816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4180 KB |
Output is correct |
2 |
Correct |
6 ms |
4268 KB |
Output is correct |
3 |
Correct |
6 ms |
4180 KB |
Output is correct |
4 |
Correct |
6 ms |
4180 KB |
Output is correct |
5 |
Correct |
5 ms |
4180 KB |
Output is correct |
6 |
Correct |
5 ms |
4180 KB |
Output is correct |
7 |
Correct |
6 ms |
4180 KB |
Output is correct |
8 |
Correct |
6 ms |
4180 KB |
Output is correct |
9 |
Correct |
5 ms |
4180 KB |
Output is correct |
10 |
Correct |
5 ms |
4180 KB |
Output is correct |
11 |
Correct |
6 ms |
4220 KB |
Output is correct |
12 |
Correct |
6 ms |
4180 KB |
Output is correct |
13 |
Correct |
6 ms |
4180 KB |
Output is correct |
14 |
Correct |
6 ms |
4228 KB |
Output is correct |
15 |
Correct |
5 ms |
4180 KB |
Output is correct |
16 |
Correct |
2 ms |
3028 KB |
Output is correct |
17 |
Correct |
3 ms |
3028 KB |
Output is correct |
18 |
Correct |
2 ms |
3028 KB |
Output is correct |
19 |
Correct |
2 ms |
3028 KB |
Output is correct |
20 |
Correct |
2 ms |
3028 KB |
Output is correct |
21 |
Correct |
283 ms |
4256 KB |
Output is correct |
22 |
Correct |
270 ms |
4172 KB |
Output is correct |
23 |
Correct |
233 ms |
4232 KB |
Output is correct |
24 |
Correct |
283 ms |
4180 KB |
Output is correct |
25 |
Correct |
277 ms |
4172 KB |
Output is correct |
26 |
Correct |
582 ms |
4340 KB |
Output is correct |
27 |
Correct |
590 ms |
4220 KB |
Output is correct |
28 |
Correct |
623 ms |
4172 KB |
Output is correct |
29 |
Correct |
622 ms |
4424 KB |
Output is correct |
30 |
Correct |
7 ms |
4284 KB |
Output is correct |
31 |
Correct |
7 ms |
4284 KB |
Output is correct |
32 |
Correct |
6 ms |
4180 KB |
Output is correct |
33 |
Correct |
7 ms |
4280 KB |
Output is correct |
34 |
Correct |
6 ms |
4288 KB |
Output is correct |
35 |
Correct |
6 ms |
4180 KB |
Output is correct |
36 |
Correct |
6 ms |
4296 KB |
Output is correct |
37 |
Correct |
6 ms |
4308 KB |
Output is correct |
38 |
Correct |
6 ms |
4308 KB |
Output is correct |
39 |
Correct |
5 ms |
812 KB |
Output is correct |
40 |
Correct |
3 ms |
852 KB |
Output is correct |
41 |
Correct |
4 ms |
852 KB |
Output is correct |
42 |
Correct |
5 ms |
852 KB |
Output is correct |
43 |
Correct |
5 ms |
852 KB |
Output is correct |
44 |
Correct |
11 ms |
828 KB |
Output is correct |
45 |
Correct |
11 ms |
852 KB |
Output is correct |
46 |
Correct |
11 ms |
852 KB |
Output is correct |
47 |
Correct |
10 ms |
864 KB |
Output is correct |
48 |
Correct |
10 ms |
852 KB |
Output is correct |
49 |
Correct |
5 ms |
852 KB |
Output is correct |
50 |
Correct |
4 ms |
852 KB |
Output is correct |
51 |
Correct |
4 ms |
852 KB |
Output is correct |
52 |
Correct |
5 ms |
852 KB |
Output is correct |
53 |
Correct |
5 ms |
852 KB |
Output is correct |
54 |
Correct |
2 ms |
724 KB |
Output is correct |
55 |
Correct |
2 ms |
820 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 |
816 KB |
Output is correct |
59 |
Correct |
478 ms |
4240 KB |
Output is correct |
60 |
Correct |
464 ms |
4212 KB |
Output is correct |
61 |
Correct |
440 ms |
4200 KB |
Output is correct |
62 |
Correct |
507 ms |
4248 KB |
Output is correct |
63 |
Correct |
482 ms |
4300 KB |
Output is correct |
64 |
Correct |
1206 ms |
4196 KB |
Output is correct |
65 |
Correct |
1210 ms |
4268 KB |
Output is correct |
66 |
Correct |
1169 ms |
4244 KB |
Output is correct |
67 |
Correct |
1137 ms |
4204 KB |
Output is correct |
68 |
Correct |
1160 ms |
4312 KB |
Output is correct |
69 |
Correct |
417 ms |
4212 KB |
Output is correct |
70 |
Correct |
415 ms |
4284 KB |
Output is correct |
71 |
Correct |
419 ms |
4196 KB |
Output is correct |
72 |
Correct |
451 ms |
4452 KB |
Output is correct |
73 |
Correct |
440 ms |
4268 KB |
Output is correct |
74 |
Correct |
52 ms |
2968 KB |
Output is correct |
75 |
Correct |
49 ms |
2952 KB |
Output is correct |
76 |
Correct |
49 ms |
2976 KB |
Output is correct |
77 |
Correct |
49 ms |
3024 KB |
Output is correct |
78 |
Correct |
51 ms |
2992 KB |
Output is correct |