제출 #1051381

#제출 시각아이디문제언어결과실행 시간메모리
1051381nisanduuTrains (BOI24_trains)C++14
8 / 100
2075 ms8024 KiB
#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 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...