#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
const int mxN = 1e5 + 10;
const int mxS = 346;
int dp[mxN], dp2[mxN][mxS + 5];
int add(int x, int y){
return ((x % mod) + (y % mod)) % mod;
}
void testCase() {
int n;
cin >> n;
vector<pair<int, int>> v(n + 1);
for(int i = 1; i <= n; ++i){
cin >> v[i].first >> v[i].second;
}
for(int i = 1; i <= n; ++i) dp[i] = 1;
for(int i = n; i >= 1; --i){
if(v[i].first == 0) {
for(int j = 1; j < mxS; ++j){
if((i + j) <= n) dp2[i][j] = add(dp2[i + j][j], dp[i]);
}
}
else{
if(v[i].first >= mxS){
for(int j = i + v[i].first; j <= n; j += v[i].first){
dp[i] = add(dp[i], dp[j]);
}
}else{
if((i + v[i].first) <= n) dp[i] = add(dp2[i + v[i].first][v[i].first], 1);
}
for(int j = 1; j < mxS; ++j){
if((i + j) <= n) dp2[i][j] = add(dp2[i + j][j], dp[i]);
}
}
}
cout << add(dp[1], mod) << "\n";
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(nullptr); cout.tie(nullptr);
testCase();
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... |