#include <bits/stdc++.h>
using namespace std;
#define dbg(x) x
#define prt(x) dbg(cerr << x)
#define pv(x) dbg(cerr << #x << " = " << x << '\n')
#define parr(x) dbg(cerr << #x << " = "; for (auto y : x) {cerr << y << ' ';} cerr << '\n';)
#define parr2d(x) dbg(cerr << #x << " = \n"; for (auto _ : x) {parr(_);} cerr << '\n';)
/*
dp[i] = # of unique paths if you get on the train at i
it's gonna be the sum of all unique paths of stuff that is a multiple of d[i] after i
as long as they are stops
if there are less than sqrt(n) stops, you can add all of them
if d[i] = 1 you could maintain a single suffix sum
if there are more than sqrt(n) stops:
???
there are still o(n) combinations of an interval & a mod, so you can't maintain all of them
actually every element only fits o(sqrt(n)) of them
so just maintain a running suffix thing of these
*/
const long long mod = 1e9 + 7;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int n;
cin >> n;
vector<int> d(n), x(n);
for (int i = 0; i < n; i++) {
cin >> d[i] >> x[i];
}
vector<long long> dp(n, 0);
for (int i = n - 1; i >= 0; i--) {
dp[i] = 1;
if (d[i] == 0) continue;
for (int j = i + d[i]; j < n && (j - i) / d[i] <= x[i]; j += d[i]) {
dp[i] += dp[j]; dp[i] %= mod;
}
}
cout << dp[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... |