This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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)
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |