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>
#define int long long
using namespace std;
const int maxn = 1e5 + 6, mod = 1e9 + 7, block = 350;
vector<int> dp(maxn, 0);
vector<vector<int>> sums(maxn, vector<int>(block, 0));
// for j : 1 -> block, sum[i][j] += DP[i]+sum[i+j][j]
signed main(){
cin.tie(nullptr) -> sync_with_stdio(0);
int n;
cin >> n;
int d[n+1], x[n+1];
for (int i = 1; i <= n; i++){
cin >> d[i] >> x[i];
}
int sum = 0;
for (int i = n; i >= 1; i--){
dp[i]=1;
if (d[i] != 0){
if (d[i] >= block){
for (int t = 1; t <= x[i] && i + t*d[i] <= n; t++){
int u = i + t*d[i];
dp[i] = (dp[u] + dp[i]) % mod;
}
}
else{
if (i + d[i] <= n){
int sumprefix = sums[i+d[i]][d[i]];
int sub = 0;
if (i + (x[i]+1)*d[i] <= n){
sub = sums[i + (x[i]+1)*d[i]][d[i]];
}
dp[i] += (sumprefix - sub + mod)%mod;
}
}
}
for (int j = 1; j < block; j++){
sums[i][j] = dp[i];
if (i + j <= n){
sums[i][j] += sums[i+j][j];
sums[i][j] %= mod;
}
}
}
cout << dp[1];
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:19:9: warning: unused variable 'sum' [-Wunused-variable]
19 | int sum = 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... |