이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 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... |