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
const long long N = 1e5 + 5;
const long long inf = 1e9;
const long long mod = 1e9 + 7;
const int Block = 300;
int n, d[N], x[N];
int dp[N], f[N][Block + 5];
signed main() {
ios_base :: sync_with_stdio (0);
cin.tie (0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> d[i] >> x[i];
}
for (int i = n; i >= 1; i--) {
dp[i] = 0;
if (d[i] == 0) {
dp[i] = 1;
}
else if (d[i] > Block) {
for (int j = i + d[i]; j <= min(n, i + d[i] * x[i]); j += d[i]) {
dp[i] = (dp[i] + dp[j]) % mod;
}
dp[i] = (dp[i] + 1) % mod;
}
else {
dp[i] = 1;
dp[i] = (dp[i] + ((i + d[i] <= n) ? (f[i + d[i]][d[i]]) : 0)) % mod;
dp[i] = (dp[i] - ((i + d[i] * (x[i] + 1) <= n) ? (f[(i + d[i] * (x[i] + 1))][d[i]]) : 0) + mod * mod) % mod;
}
for (int j = 0; j <= Block; j++) {
f[i][j] = ((i + j <= n ? f[i + j][j] : 0) + dp[i]) % mod;
}
}
cout << dp[1];
}
# | 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... |