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>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
const ll mod=1e9+7,N=5e2+5;
ll binpow(ll a,ll b){
ll res=1;
while(b){
if(b&1){
res=res*a%mod;
}
a=a*a%mod;
b=b>>1;
}
return res;
}
ll inv(ll a){
return binpow(a,mod-2);
}
ll fact[N],invfact[N],C[N][N];
vector<ll>v;
void init(){
fact[0]=1;
for(ll i=1;i<N;i++){
fact[i]=fact[i-1]*i%mod;
}
invfact[N-1]=inv(fact[N-1]);
for(ll i=N-1;i>=1;i--){
invfact[i-1]=invfact[i]*i%mod;
}
for(ll i=0;i<v.size();i++){
ll cur=1,L=1,R=v[i];
for(ll j=1;j<N;j++){
if(j>v[i]){
cur=0;
}
else{
cur=cur*R%mod*inv(L)%mod;
R--;
L++;
}
C[i+1][j]=cur;
}
}
}
ll nCk(ll i,ll k){
return C[i][k];
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n;
cin>>n;
ll a[n+5],b[n+5];
set<ll>s;
for(ll i=1;i<=n;i++){
cin>>a[i]>>b[i];
s.insert(a[i]);
s.insert(b[i]+1);
}
ll cur=0;
ll l[2*n+5];
for(auto x:s){
cur++;
l[cur]=x;
}
for(ll i=1;i<cur;i++){
v.pb(l[i+1]-l[i]);
}
init();
ll dp[2*n+5][n+5],sum[2*n+5][n+5];
memset(sum,0,sizeof sum);
ll ans=0;
for(ll i=1;i<=n;i++){
ll tot=1;
memset(dp,0,sizeof dp);
for(ll j=1;j<cur;j++){//l[j] l[j+1]-1
if(b[i]>=l[j]&&a[i]<l[j+1]){
dp[j][1]=tot;
for(ll k=2;k<=n;k++){
dp[j][k]=sum[j][k-1];
}
}
for(ll k=1;k<=n;k++){
tot+=sum[j][k]*nCk(j,k)%mod;
tot%=mod;
}
for(ll k=1;k<=n;k++){
sum[j][k]+=dp[j][k];
sum[j][k]%=mod;
}
}
}
for(ll j=1;j<cur;j++){
for(ll k=1;k<=n;k++){
ans+=sum[j][k]*nCk(j,k)%mod;
ans%=mod;
}
}
cout<<ans;
}
Compilation message (stderr)
boat.cpp: In function 'void init()':
boat.cpp:42:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(ll 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... |