#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define a first
#define b second
#define pb push_back
llo n,aa,bb;
map<llo,llo> dd;
llo si[2001];
llo mod=1000000007;
vector<llo> cc;
vector<pair<llo,llo>> it;
llo fac[501];
llo fac2[501];
llo pre[2001][501];
llo pre2[2001][501];
llo com[501][501];
llo dp[501][2001];
llo ind2=0;
llo mod2(llo ee,llo ff){
if(ff==0){
return 1;
}
llo ans=mod2(ee,ff/2);
ans*=ans;
ans%=mod;
if(ff%2==1){
ans*=ee;
ans%=mod;
}
return ans;
}
void comp(){
fac[0]=1;
for(llo i=1;i<501;i++){
fac[i]=fac[i-1]*i;
fac[i]%=mod;
}
for(llo i=0;i<501;i++){
fac2[i]=mod2(fac[i],mod-2);
}
}
void ncr(){
for(llo i=0;i<n+1;i++){
for(llo j=0;j<=i;j++){
com[i][j]=fac2[j]*fac2[i-j];
com[i][j]%=mod;
com[i][j]*=fac[i];
com[i][j]%=mod;
}
}
}
void comp2(){
fac[0]=1;
for(llo i=0;i<ind2;i++){
llo cur=1;
pre[i][0]=0;
for(llo j=1;j<n+1;j++){
if(j<=si[i]){
cur*=mod2(j,mod-2);
cur%=mod;
cur*=(si[i]-j+1);
cur%=mod;
pre[i][j]=cur;
}
else{
pre[i][j]=0;
}
}
}
for(llo i=0;i<ind2;i++){
for(llo j=1;j<n+1;j++){
pre2[i][j]=0;
int l=0;
for(llo k=1;k<=j;k++){
pre2[i][j]+=pre[i][k]*com[j-1][k-1];
l+=1;
if(l==10){
l=0;
pre2[i][j]%=mod;
}
}
pre2[i][j]%=mod;
}
}
}
int main(){
cin>>n;
for(llo i=0;i<n;i++){
cin>>aa>>bb;
cc.pb(aa);
cc.pb(bb);
it.pb({aa,bb});
}
comp();//factorial
ncr();//computing iCj for i and j from 1 to n
sort(cc.begin(),cc.end());
for(llo i=0;i<cc.size();i++){
if(i<cc.size()-1 and cc[i]==cc[i+1]){
continue;
}
dd[cc[i]]=ind2;
ind2+=1;
si[dd[cc[i]]]=1;
if(i<cc.size()-1){
if(cc[i]<cc[i+1]-1){
si[ind2]=cc[i+1]-cc[i]-1;
ind2+=1;
}
}
}
comp2();
for(llo i=0;i<n;i++){
it[i].a=dd[it[i].a];
it[i].b=dd[it[i].b];
}
for(llo i=0;i<n;i++){
for(llo j=0;j<ind2;j++){
dp[i][j]=0;
}
}
for(llo j=0;j<ind2;j++){
if(j>=it[0].a and j<=it[0].b){
dp[0][j]=si[j];
}
if(j>0){
dp[0][j]+=dp[0][j-1];
}
dp[0][j]%=mod;
}
for(llo i=1;i<n;i++){
for(llo j=it[i].a;j<=it[i].b;j++){
llo cot=1;
int l=0;
for(llo k=i-1;k>=0;k--){
if(j>0){
dp[i][j]+=(dp[k][j-1])*pre2[j][cot];
// dp[i][j]%=mod;
if(l==10){
dp[i][j]%=mod;
l=0;
}
l+=1;
}
if(it[k].a<=j and j<=it[k].b){
cot+=1;
}
}
dp[i][j]+=pre2[j][cot];
dp[i][j]%=mod;
}
for(llo j=1;j<ind2;j++){
dp[i][j]+=dp[i][j-1];
dp[i][j]%=mod;
}
}
llo ans=0;
for(llo i=0;i<n;i++){
ans+=dp[i][ind2-1];
ans%=mod;
}
cout<<ans<<endl;
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:102:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(llo i=0;i<cc.size();i++){
~^~~~~~~~~~
boat.cpp:103:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(i<cc.size()-1 and cc[i]==cc[i+1]){
~^~~~~~~~~~~~
boat.cpp:110:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(i<cc.size()-1){
~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
297 ms |
16248 KB |
Output is correct |
2 |
Correct |
295 ms |
16120 KB |
Output is correct |
3 |
Correct |
295 ms |
16120 KB |
Output is correct |
4 |
Correct |
297 ms |
16120 KB |
Output is correct |
5 |
Correct |
299 ms |
16248 KB |
Output is correct |
6 |
Correct |
299 ms |
16120 KB |
Output is correct |
7 |
Correct |
298 ms |
16120 KB |
Output is correct |
8 |
Correct |
297 ms |
16120 KB |
Output is correct |
9 |
Correct |
297 ms |
16120 KB |
Output is correct |
10 |
Correct |
293 ms |
16120 KB |
Output is correct |
11 |
Correct |
300 ms |
16248 KB |
Output is correct |
12 |
Correct |
297 ms |
16120 KB |
Output is correct |
13 |
Correct |
297 ms |
16120 KB |
Output is correct |
14 |
Correct |
297 ms |
16164 KB |
Output is correct |
15 |
Correct |
299 ms |
16120 KB |
Output is correct |
16 |
Correct |
60 ms |
6392 KB |
Output is correct |
17 |
Correct |
64 ms |
6648 KB |
Output is correct |
18 |
Correct |
62 ms |
6392 KB |
Output is correct |
19 |
Correct |
65 ms |
6520 KB |
Output is correct |
20 |
Correct |
62 ms |
6520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
297 ms |
16248 KB |
Output is correct |
2 |
Correct |
295 ms |
16120 KB |
Output is correct |
3 |
Correct |
295 ms |
16120 KB |
Output is correct |
4 |
Correct |
297 ms |
16120 KB |
Output is correct |
5 |
Correct |
299 ms |
16248 KB |
Output is correct |
6 |
Correct |
299 ms |
16120 KB |
Output is correct |
7 |
Correct |
298 ms |
16120 KB |
Output is correct |
8 |
Correct |
297 ms |
16120 KB |
Output is correct |
9 |
Correct |
297 ms |
16120 KB |
Output is correct |
10 |
Correct |
293 ms |
16120 KB |
Output is correct |
11 |
Correct |
300 ms |
16248 KB |
Output is correct |
12 |
Correct |
297 ms |
16120 KB |
Output is correct |
13 |
Correct |
297 ms |
16120 KB |
Output is correct |
14 |
Correct |
297 ms |
16164 KB |
Output is correct |
15 |
Correct |
299 ms |
16120 KB |
Output is correct |
16 |
Correct |
60 ms |
6392 KB |
Output is correct |
17 |
Correct |
64 ms |
6648 KB |
Output is correct |
18 |
Correct |
62 ms |
6392 KB |
Output is correct |
19 |
Correct |
65 ms |
6520 KB |
Output is correct |
20 |
Correct |
62 ms |
6520 KB |
Output is correct |
21 |
Correct |
431 ms |
23392 KB |
Output is correct |
22 |
Correct |
434 ms |
23416 KB |
Output is correct |
23 |
Correct |
418 ms |
23300 KB |
Output is correct |
24 |
Correct |
435 ms |
23416 KB |
Output is correct |
25 |
Correct |
423 ms |
23160 KB |
Output is correct |
26 |
Correct |
467 ms |
22648 KB |
Output is correct |
27 |
Correct |
476 ms |
22648 KB |
Output is correct |
28 |
Correct |
479 ms |
22652 KB |
Output is correct |
29 |
Correct |
482 ms |
22776 KB |
Output is correct |
30 |
Correct |
406 ms |
24908 KB |
Output is correct |
31 |
Correct |
409 ms |
24808 KB |
Output is correct |
32 |
Correct |
408 ms |
24692 KB |
Output is correct |
33 |
Correct |
418 ms |
24696 KB |
Output is correct |
34 |
Correct |
408 ms |
24696 KB |
Output is correct |
35 |
Correct |
286 ms |
16120 KB |
Output is correct |
36 |
Correct |
286 ms |
16120 KB |
Output is correct |
37 |
Correct |
287 ms |
16120 KB |
Output is correct |
38 |
Correct |
291 ms |
16120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
4608 KB |
Output is correct |
2 |
Correct |
23 ms |
4600 KB |
Output is correct |
3 |
Correct |
20 ms |
4608 KB |
Output is correct |
4 |
Correct |
31 ms |
4608 KB |
Output is correct |
5 |
Correct |
22 ms |
4540 KB |
Output is correct |
6 |
Correct |
21 ms |
4608 KB |
Output is correct |
7 |
Correct |
21 ms |
4608 KB |
Output is correct |
8 |
Correct |
22 ms |
4608 KB |
Output is correct |
9 |
Correct |
21 ms |
4608 KB |
Output is correct |
10 |
Correct |
21 ms |
4608 KB |
Output is correct |
11 |
Correct |
21 ms |
4608 KB |
Output is correct |
12 |
Correct |
20 ms |
4608 KB |
Output is correct |
13 |
Correct |
22 ms |
4608 KB |
Output is correct |
14 |
Correct |
21 ms |
4608 KB |
Output is correct |
15 |
Correct |
20 ms |
4608 KB |
Output is correct |
16 |
Correct |
12 ms |
2688 KB |
Output is correct |
17 |
Correct |
12 ms |
2560 KB |
Output is correct |
18 |
Correct |
12 ms |
2560 KB |
Output is correct |
19 |
Correct |
12 ms |
2560 KB |
Output is correct |
20 |
Correct |
12 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
297 ms |
16248 KB |
Output is correct |
2 |
Correct |
295 ms |
16120 KB |
Output is correct |
3 |
Correct |
295 ms |
16120 KB |
Output is correct |
4 |
Correct |
297 ms |
16120 KB |
Output is correct |
5 |
Correct |
299 ms |
16248 KB |
Output is correct |
6 |
Correct |
299 ms |
16120 KB |
Output is correct |
7 |
Correct |
298 ms |
16120 KB |
Output is correct |
8 |
Correct |
297 ms |
16120 KB |
Output is correct |
9 |
Correct |
297 ms |
16120 KB |
Output is correct |
10 |
Correct |
293 ms |
16120 KB |
Output is correct |
11 |
Correct |
300 ms |
16248 KB |
Output is correct |
12 |
Correct |
297 ms |
16120 KB |
Output is correct |
13 |
Correct |
297 ms |
16120 KB |
Output is correct |
14 |
Correct |
297 ms |
16164 KB |
Output is correct |
15 |
Correct |
299 ms |
16120 KB |
Output is correct |
16 |
Correct |
60 ms |
6392 KB |
Output is correct |
17 |
Correct |
64 ms |
6648 KB |
Output is correct |
18 |
Correct |
62 ms |
6392 KB |
Output is correct |
19 |
Correct |
65 ms |
6520 KB |
Output is correct |
20 |
Correct |
62 ms |
6520 KB |
Output is correct |
21 |
Correct |
431 ms |
23392 KB |
Output is correct |
22 |
Correct |
434 ms |
23416 KB |
Output is correct |
23 |
Correct |
418 ms |
23300 KB |
Output is correct |
24 |
Correct |
435 ms |
23416 KB |
Output is correct |
25 |
Correct |
423 ms |
23160 KB |
Output is correct |
26 |
Correct |
467 ms |
22648 KB |
Output is correct |
27 |
Correct |
476 ms |
22648 KB |
Output is correct |
28 |
Correct |
479 ms |
22652 KB |
Output is correct |
29 |
Correct |
482 ms |
22776 KB |
Output is correct |
30 |
Correct |
406 ms |
24908 KB |
Output is correct |
31 |
Correct |
409 ms |
24808 KB |
Output is correct |
32 |
Correct |
408 ms |
24692 KB |
Output is correct |
33 |
Correct |
418 ms |
24696 KB |
Output is correct |
34 |
Correct |
408 ms |
24696 KB |
Output is correct |
35 |
Correct |
286 ms |
16120 KB |
Output is correct |
36 |
Correct |
286 ms |
16120 KB |
Output is correct |
37 |
Correct |
287 ms |
16120 KB |
Output is correct |
38 |
Correct |
291 ms |
16120 KB |
Output is correct |
39 |
Correct |
21 ms |
4608 KB |
Output is correct |
40 |
Correct |
23 ms |
4600 KB |
Output is correct |
41 |
Correct |
20 ms |
4608 KB |
Output is correct |
42 |
Correct |
31 ms |
4608 KB |
Output is correct |
43 |
Correct |
22 ms |
4540 KB |
Output is correct |
44 |
Correct |
21 ms |
4608 KB |
Output is correct |
45 |
Correct |
21 ms |
4608 KB |
Output is correct |
46 |
Correct |
22 ms |
4608 KB |
Output is correct |
47 |
Correct |
21 ms |
4608 KB |
Output is correct |
48 |
Correct |
21 ms |
4608 KB |
Output is correct |
49 |
Correct |
21 ms |
4608 KB |
Output is correct |
50 |
Correct |
20 ms |
4608 KB |
Output is correct |
51 |
Correct |
22 ms |
4608 KB |
Output is correct |
52 |
Correct |
21 ms |
4608 KB |
Output is correct |
53 |
Correct |
20 ms |
4608 KB |
Output is correct |
54 |
Correct |
12 ms |
2688 KB |
Output is correct |
55 |
Correct |
12 ms |
2560 KB |
Output is correct |
56 |
Correct |
12 ms |
2560 KB |
Output is correct |
57 |
Correct |
12 ms |
2560 KB |
Output is correct |
58 |
Correct |
12 ms |
2688 KB |
Output is correct |
59 |
Correct |
803 ms |
26084 KB |
Output is correct |
60 |
Correct |
809 ms |
25976 KB |
Output is correct |
61 |
Correct |
789 ms |
25976 KB |
Output is correct |
62 |
Correct |
800 ms |
25976 KB |
Output is correct |
63 |
Correct |
810 ms |
25848 KB |
Output is correct |
64 |
Correct |
905 ms |
25976 KB |
Output is correct |
65 |
Correct |
906 ms |
26020 KB |
Output is correct |
66 |
Correct |
903 ms |
26104 KB |
Output is correct |
67 |
Correct |
908 ms |
26036 KB |
Output is correct |
68 |
Correct |
900 ms |
26104 KB |
Output is correct |
69 |
Correct |
754 ms |
25976 KB |
Output is correct |
70 |
Correct |
745 ms |
25848 KB |
Output is correct |
71 |
Correct |
732 ms |
25976 KB |
Output is correct |
72 |
Correct |
750 ms |
25980 KB |
Output is correct |
73 |
Correct |
744 ms |
26104 KB |
Output is correct |
74 |
Correct |
94 ms |
6648 KB |
Output is correct |
75 |
Correct |
99 ms |
6776 KB |
Output is correct |
76 |
Correct |
105 ms |
6648 KB |
Output is correct |
77 |
Correct |
96 ms |
6648 KB |
Output is correct |
78 |
Correct |
99 ms |
6776 KB |
Output is correct |