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
vector<pair<int, int>> vals;
vector<int> dp;
int ways(int n)
{
if (dp[n] != -1) return dp[n];
if (vals[n].first == 0 || n + vals[n].first >= (int)dp.size()) return dp[n] = 1;
int ans = 1;
for (int i = n + vals[n].first, t = 0; i < (int)dp.size() && t < vals[n].second; i += vals[n].first, t++)
{
ans += ways(i);
ans %= 1000000007;
}
return dp[n] = ans;
}
signed main()
{
int N, a, b;
cin >> N;
dp = vector<int>(N, -1);
for (int i = 0; i < N; i++)
{
cin >> a >> b;
vals.push_back({a, b});
}
cout << ways(0) << '\n';
}
# | 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... |