#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define LL long long
#define st first
#define nd second
#define endl '\n'
using namespace std;
const int MAXN=505,mod=1e9+7;
int inverse[MAXN],dp[MAXN][MAXN*3],n,a[MAXN],b[MAXN];
vector<int> v;
void add(int &x,int y) {
x+=y;
if(x>=mod)
x-=mod;
}
int bpow(int x,int y) {
LL ret=1,t=x;
while(y) {
if(y&1)
ret=(ret*t)%mod;
y>>=1;
t=(t*t)%mod;
}
return (int)ret;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;++i) {
cin>>a[i]>>b[i];
v.pb(a[i]);
v.pb(b[i]+1);
inverse[i]=bpow(i,mod-2);
}
v.pb(0);
sort(v.begin(),v.end());
v.resize(unique(v.begin(),v.end())-v.begin());
for(int i=1;i<=n;++i) {
a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin();
b[i]=lower_bound(v.begin(),v.end(),b[i]+1)-v.begin();
}
for(int i=0;i<v.size();++i)
dp[n+1][i]=1;
for(int i=n;i>=1;--i) {
for(int j=v.size()-2;j>=1;--j) {
add(dp[i][j],dp[i][j+1]);
if(!(j>=a[i]&&j<b[i]))
continue;
LL nCr=1,x=v[j+1]-v[j],y=1;
for(int k=i;k<=n;++k) {
if(j>=a[k]&&j<b[k]) {
nCr=(nCr*x)%mod;
nCr=(nCr*inverse[y])%mod;
++x; ++y;
}
add(dp[i][j],(nCr*dp[k+1][j+1])%mod);
}
//cout<<i<<" "<<j<<" "<<v[j]<<" "<<dp[i][j]<<endl;
}
}
int ans=0;
for(int i=1;i<=n;++i)
add(ans,dp[i][1]);
cout<<ans<< endl;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:54:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v.size();++i)
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5176 KB |
Output is correct |
2 |
Correct |
0 ms |
5176 KB |
Output is correct |
3 |
Correct |
6 ms |
5176 KB |
Output is correct |
4 |
Correct |
6 ms |
5176 KB |
Output is correct |
5 |
Correct |
6 ms |
5176 KB |
Output is correct |
6 |
Correct |
3 ms |
5176 KB |
Output is correct |
7 |
Correct |
3 ms |
5176 KB |
Output is correct |
8 |
Correct |
3 ms |
5176 KB |
Output is correct |
9 |
Correct |
3 ms |
5176 KB |
Output is correct |
10 |
Correct |
3 ms |
5176 KB |
Output is correct |
11 |
Correct |
3 ms |
5176 KB |
Output is correct |
12 |
Correct |
3 ms |
5176 KB |
Output is correct |
13 |
Correct |
6 ms |
5176 KB |
Output is correct |
14 |
Correct |
6 ms |
5176 KB |
Output is correct |
15 |
Correct |
6 ms |
5176 KB |
Output is correct |
16 |
Correct |
0 ms |
5176 KB |
Output is correct |
17 |
Correct |
0 ms |
5176 KB |
Output is correct |
18 |
Correct |
3 ms |
5176 KB |
Output is correct |
19 |
Correct |
0 ms |
5176 KB |
Output is correct |
20 |
Correct |
3 ms |
5176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5176 KB |
Output is correct |
2 |
Correct |
0 ms |
5176 KB |
Output is correct |
3 |
Correct |
6 ms |
5176 KB |
Output is correct |
4 |
Correct |
6 ms |
5176 KB |
Output is correct |
5 |
Correct |
6 ms |
5176 KB |
Output is correct |
6 |
Correct |
3 ms |
5176 KB |
Output is correct |
7 |
Correct |
3 ms |
5176 KB |
Output is correct |
8 |
Correct |
3 ms |
5176 KB |
Output is correct |
9 |
Correct |
3 ms |
5176 KB |
Output is correct |
10 |
Correct |
3 ms |
5176 KB |
Output is correct |
11 |
Correct |
3 ms |
5176 KB |
Output is correct |
12 |
Correct |
3 ms |
5176 KB |
Output is correct |
13 |
Correct |
6 ms |
5176 KB |
Output is correct |
14 |
Correct |
6 ms |
5176 KB |
Output is correct |
15 |
Correct |
6 ms |
5176 KB |
Output is correct |
16 |
Correct |
0 ms |
5176 KB |
Output is correct |
17 |
Correct |
0 ms |
5176 KB |
Output is correct |
18 |
Correct |
3 ms |
5176 KB |
Output is correct |
19 |
Correct |
0 ms |
5176 KB |
Output is correct |
20 |
Correct |
3 ms |
5176 KB |
Output is correct |
21 |
Correct |
863 ms |
5176 KB |
Output is correct |
22 |
Correct |
806 ms |
5176 KB |
Output is correct |
23 |
Correct |
736 ms |
5176 KB |
Output is correct |
24 |
Correct |
773 ms |
5176 KB |
Output is correct |
25 |
Correct |
819 ms |
5176 KB |
Output is correct |
26 |
Correct |
1146 ms |
5176 KB |
Output is correct |
27 |
Correct |
1063 ms |
5176 KB |
Output is correct |
28 |
Correct |
1033 ms |
5176 KB |
Output is correct |
29 |
Correct |
1136 ms |
5176 KB |
Output is correct |
30 |
Correct |
9 ms |
5176 KB |
Output is correct |
31 |
Correct |
6 ms |
5176 KB |
Output is correct |
32 |
Correct |
9 ms |
5176 KB |
Output is correct |
33 |
Correct |
9 ms |
5176 KB |
Output is correct |
34 |
Correct |
9 ms |
5176 KB |
Output is correct |
35 |
Correct |
6 ms |
5176 KB |
Output is correct |
36 |
Correct |
9 ms |
5176 KB |
Output is correct |
37 |
Correct |
9 ms |
5176 KB |
Output is correct |
38 |
Correct |
9 ms |
5176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5176 KB |
Output is correct |
2 |
Correct |
3 ms |
5176 KB |
Output is correct |
3 |
Correct |
6 ms |
5176 KB |
Output is correct |
4 |
Correct |
6 ms |
5176 KB |
Output is correct |
5 |
Correct |
6 ms |
5176 KB |
Output is correct |
6 |
Correct |
9 ms |
5176 KB |
Output is correct |
7 |
Correct |
9 ms |
5176 KB |
Output is correct |
8 |
Correct |
9 ms |
5176 KB |
Output is correct |
9 |
Correct |
9 ms |
5176 KB |
Output is correct |
10 |
Correct |
6 ms |
5176 KB |
Output is correct |
11 |
Correct |
6 ms |
5176 KB |
Output is correct |
12 |
Correct |
6 ms |
5176 KB |
Output is correct |
13 |
Correct |
6 ms |
5176 KB |
Output is correct |
14 |
Correct |
6 ms |
5176 KB |
Output is correct |
15 |
Correct |
6 ms |
5176 KB |
Output is correct |
16 |
Correct |
3 ms |
5176 KB |
Output is correct |
17 |
Correct |
3 ms |
5176 KB |
Output is correct |
18 |
Correct |
3 ms |
5176 KB |
Output is correct |
19 |
Correct |
3 ms |
5176 KB |
Output is correct |
20 |
Correct |
3 ms |
5176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5176 KB |
Output is correct |
2 |
Correct |
0 ms |
5176 KB |
Output is correct |
3 |
Correct |
6 ms |
5176 KB |
Output is correct |
4 |
Correct |
6 ms |
5176 KB |
Output is correct |
5 |
Correct |
6 ms |
5176 KB |
Output is correct |
6 |
Correct |
3 ms |
5176 KB |
Output is correct |
7 |
Correct |
3 ms |
5176 KB |
Output is correct |
8 |
Correct |
3 ms |
5176 KB |
Output is correct |
9 |
Correct |
3 ms |
5176 KB |
Output is correct |
10 |
Correct |
3 ms |
5176 KB |
Output is correct |
11 |
Correct |
3 ms |
5176 KB |
Output is correct |
12 |
Correct |
3 ms |
5176 KB |
Output is correct |
13 |
Correct |
6 ms |
5176 KB |
Output is correct |
14 |
Correct |
6 ms |
5176 KB |
Output is correct |
15 |
Correct |
6 ms |
5176 KB |
Output is correct |
16 |
Correct |
0 ms |
5176 KB |
Output is correct |
17 |
Correct |
0 ms |
5176 KB |
Output is correct |
18 |
Correct |
3 ms |
5176 KB |
Output is correct |
19 |
Correct |
0 ms |
5176 KB |
Output is correct |
20 |
Correct |
3 ms |
5176 KB |
Output is correct |
21 |
Correct |
863 ms |
5176 KB |
Output is correct |
22 |
Correct |
806 ms |
5176 KB |
Output is correct |
23 |
Correct |
736 ms |
5176 KB |
Output is correct |
24 |
Correct |
773 ms |
5176 KB |
Output is correct |
25 |
Correct |
819 ms |
5176 KB |
Output is correct |
26 |
Correct |
1146 ms |
5176 KB |
Output is correct |
27 |
Correct |
1063 ms |
5176 KB |
Output is correct |
28 |
Correct |
1033 ms |
5176 KB |
Output is correct |
29 |
Correct |
1136 ms |
5176 KB |
Output is correct |
30 |
Correct |
9 ms |
5176 KB |
Output is correct |
31 |
Correct |
6 ms |
5176 KB |
Output is correct |
32 |
Correct |
9 ms |
5176 KB |
Output is correct |
33 |
Correct |
9 ms |
5176 KB |
Output is correct |
34 |
Correct |
9 ms |
5176 KB |
Output is correct |
35 |
Correct |
6 ms |
5176 KB |
Output is correct |
36 |
Correct |
9 ms |
5176 KB |
Output is correct |
37 |
Correct |
9 ms |
5176 KB |
Output is correct |
38 |
Correct |
9 ms |
5176 KB |
Output is correct |
39 |
Correct |
3 ms |
5176 KB |
Output is correct |
40 |
Correct |
3 ms |
5176 KB |
Output is correct |
41 |
Correct |
6 ms |
5176 KB |
Output is correct |
42 |
Correct |
6 ms |
5176 KB |
Output is correct |
43 |
Correct |
6 ms |
5176 KB |
Output is correct |
44 |
Correct |
9 ms |
5176 KB |
Output is correct |
45 |
Correct |
9 ms |
5176 KB |
Output is correct |
46 |
Correct |
9 ms |
5176 KB |
Output is correct |
47 |
Correct |
9 ms |
5176 KB |
Output is correct |
48 |
Correct |
6 ms |
5176 KB |
Output is correct |
49 |
Correct |
6 ms |
5176 KB |
Output is correct |
50 |
Correct |
6 ms |
5176 KB |
Output is correct |
51 |
Correct |
6 ms |
5176 KB |
Output is correct |
52 |
Correct |
6 ms |
5176 KB |
Output is correct |
53 |
Correct |
6 ms |
5176 KB |
Output is correct |
54 |
Correct |
3 ms |
5176 KB |
Output is correct |
55 |
Correct |
3 ms |
5176 KB |
Output is correct |
56 |
Correct |
3 ms |
5176 KB |
Output is correct |
57 |
Correct |
3 ms |
5176 KB |
Output is correct |
58 |
Correct |
3 ms |
5176 KB |
Output is correct |
59 |
Correct |
969 ms |
5176 KB |
Output is correct |
60 |
Correct |
843 ms |
5176 KB |
Output is correct |
61 |
Correct |
773 ms |
5176 KB |
Output is correct |
62 |
Correct |
823 ms |
5176 KB |
Output is correct |
63 |
Correct |
933 ms |
5176 KB |
Output is correct |
64 |
Correct |
1296 ms |
5176 KB |
Output is correct |
65 |
Correct |
1233 ms |
5176 KB |
Output is correct |
66 |
Correct |
1146 ms |
5176 KB |
Output is correct |
67 |
Correct |
1226 ms |
5176 KB |
Output is correct |
68 |
Correct |
1149 ms |
5176 KB |
Output is correct |
69 |
Correct |
753 ms |
5176 KB |
Output is correct |
70 |
Correct |
709 ms |
5176 KB |
Output is correct |
71 |
Correct |
703 ms |
5176 KB |
Output is correct |
72 |
Correct |
889 ms |
5176 KB |
Output is correct |
73 |
Correct |
836 ms |
5176 KB |
Output is correct |
74 |
Correct |
146 ms |
5176 KB |
Output is correct |
75 |
Correct |
156 ms |
5176 KB |
Output is correct |
76 |
Correct |
163 ms |
5176 KB |
Output is correct |
77 |
Correct |
166 ms |
5176 KB |
Output is correct |
78 |
Correct |
169 ms |
5176 KB |
Output is correct |