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