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;
constexpr int64_t N = 1e5+5;
constexpr int64_t mod = 1e9+7;
int64_t dp[N+5]{};//number of paths starting from i
constexpr int64_t d=320;
int64_t c[N+5][d+5]{};//sum dp given (start pos, step size)
int main() {
int64_t n;
cin>>n;
int64_t a[n+1],b[n+1];
for(int64_t i=1;i<=n;i++){
cin>>a[i]>>b[i];
}
for(int64_t i=n;i>0;i--){
dp[i]=1;
if(a[i]){
if(a[i]>=d){
for(int64_t j=1;j<=b[i];j++){
int64_t pos=i+j*a[i];
if(pos>n)break;
dp[i]=(dp[i]+dp[pos])%mod;
}
}
else{
int64_t fin = min(i+a[i]*b[i],n);
dp[i]=(dp[i]+c[i][a[i]]-c[fin][a[i]]+mod)%mod;
}
}
//update c state
for(int64_t j=1;j<d;j++){
if(i-j<1)break;
c[i-j][j]=(c[i][j]+dp[i])%mod;
}
}
cout<<dp[1]%mod<<' ';
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |