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;
typedef long long ll;
ll mod = 1e9 + 7;
ll f(ll cr,ll n,map<ll,ll> &x,map<ll,ll> &d,vector<ll>&dp){
    if(cr>n) return 0;
    ll am = 1;
    if(d[cr]==0) return am;
    if(dp[cr]!=-1) return dp[cr];
    
    for(ll i=1;i<=x[cr];i++){
        ll newDes = cr + i*d[cr];
        if(newDes>n) break;
        am = (am + f(newDes,n,x,d,dp))%mod;
    } 
    return dp[cr] = (am)%mod;
}
void solve(){
    ll n;
    cin>>n;
    map<ll,ll> d,x;
    vector<ll> dp(1e5 + 10,-1);
    for(ll i=1;i<=n;i++){
        ll a,b;
        cin>>a>>b;
        d[i]=a;
        x[i]=b;
    }
    ll ans = f(1,n,x,d,dp);
    cout<<ans<<endl;
}
int main()
{
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    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... |