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;
const long long rad = 316;
const long long mod = 1e9+7;
long long solve(long long N, vector<long long> &d, vector<long long> &x) {
vector<vector<long long>> pr(rad, vector<long long> (N+rad, 0));
vector<long long> dp(N, 1);
for (int i = N-1; i >= 0; i--) {
if (x[i] >= rad) {
for (int k = i+x[i]; k < min(N, i+d[i]*x[i]+1); k+= x[i]) {
dp[i] += dp[k];
dp[i] %= mod;
}
}
else {
if (d[i] > 0) {
dp[i] += pr[x[i]][i+x[i]]-pr[x[i]][i+(d[i]+1)*x[i]];
while (dp[i] < 0) dp[i] += mod;
dp[i] %= mod;
}
}
for (int j = 1; j < rad; j++) {
if (i+j < N) {
pr[j][i] = dp[i]+pr[j][i+j];
pr[j][i] %= mod;
} else pr[j][i] = dp[i];
}
}
return dp[0];
}
int main() {
long long N; cin >> N;
vector<long long> d(N), x(N);
for (int i = 0; i < N; i++) cin >> x[i] >> d[i];
for (int i = 0; i < N; i++) {
if (x[i] == 0) d[i] = 0;
else d[i] = min(d[i], (N-i-1)/x[i]);
}
cout << (solve(N, d, x));
}
# | 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... |