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;
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];
ll ans=0;
vector<ll>dp[n+5];
for(ll i=1;i<=n;i++){
cin>>a[i]>>b[i];
dp[i].resize(b[i]-a[i]+1);
}
dp[0].pb(1);//first is 0,then ai, ... ,bi
for(ll i=1;i<=n;i++){
ll tot=1;
dp[i][0]=1;
ll c[n+5];
for(ll j=1;j<=n;j++){
c[j]=a[j];
}
for(ll j=a[i];j<=b[i];j++){
for(ll k=1;k<i;k++){
while(c[k]<j&&c[k]<=b[i]){
tot+=dp[k][c[k]-a[k]+1];
tot%=mod;
c[k]++;
}
}
dp[i][j-a[i]+1]=tot;
ans+=dp[i][j-a[i]+1];
ans%=mod;
}
}
cout<<ans<<"\n";
}
# | 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... |