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 int long long
int const N=1e5+5;
int const mod=1e9+7;
int dp[N],suf[N],d[N],x[N];
int n;
void solve12(){
dp[n]=1;
for(int i=n-1;i>=1;i--){
dp[i]=1;
if(d[i]==0)
continue;
for(int j=i+d[i];j<=min(i+(d[i]*x[i]),n);j+=d[i])
dp[i]=(dp[i]+dp[j])%mod;
}
cout<<dp[1]<<endl;
}
void solve3(){
dp[n]=1;
suf[n]=1;
for(int i=n-1;i>=1;i--){
dp[i]=(((1+suf[i+1]-suf[min(n+1,i+x[i]+1)])%mod)+mod)%mod;
suf[i]=(dp[i]+suf[i+1])%mod;
}
cout<<dp[1]<<endl;
}
void solve4(){
dp[n]=1;
suf[n]=1;
for(int i=n-1;i>=1;i--){
dp[i]=1;
if(d[i]==0){
suf[i]=1;
continue;
}
for(int j=i+d[i];j<=n;j+=d[i]){
if(d[j]==d[i]){
dp[i]=(dp[i]+suf[j])%mod;
break;
}
dp[i]=(dp[i]+dp[j])%mod;
}
suf[i]=((dp[i]*2)%mod + (mod-1))%mod;
}
// for(int i=1;i<=n;i++)
// cout<<dp[i]<<endl;
cout<<dp[1]<<endl;
}
signed main(){
cin>>n;
bool b=1;
for (int i = 1; i <=n; ++i){
cin>>d[i]>>x[i];
if(d[i]!=1)
b=0;
}
if(n<=10000)
solve12();
else if(b)
solve3();
else
solve4();
return 0;
}
# | 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... |