#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 9e18
#define M 1000000007
void solve() {
int n;
cin >> n;
vector<int> d(n + 1), x(n + 1);
bool sub3 = true;
for (int i = 1; i <= n; i++) {
cin >> d[i] >> x[i];
if (d[i] != 1) sub3 = false;
}
if (sub3) {
vector<int> dp(n + 1, 1);
vector<int> dpp(n + 2);
dpp[n] = 1;
for (int i = n - 1; i >= 1; i--) {
dp[i] = (dp[i] + dpp[i + 1] - dpp[min(i + x[i] + 1, n + 1)]) % M;
dpp[i] = (dpp[i + 1] + dp[i]) % M;
}
cout << dp[1];
return;
}
vector<vector<int>> routes(n + 1);
for (int i = 1; i <= n; i++) {
for (int j = i + d[i]; j <= n; j += d[i]) {
if (routes[i].size() == x[i] || d[i] == 0) break;
routes[i].push_back(j);
}
}
vector<int> dp(n + 1, 1);
for (int i = n; i >= 1; i--) {
for (int j : routes[i]) {
dp[i] = (dp[i] + dp[j]) % M;
}
}
cout << dp[1];
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
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... |