Submission #1051383

#TimeUsernameProblemLanguageResultExecution timeMemory
1051383nisanduuTrains (BOI24_trains)C++14
21 / 100
2100 ms10588 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
ll f(ll cr,ll n,vector<ll> &x,vector<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;
    vector<ll> d(1e5 + 10),x(1e5 + 10);
    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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...