#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define ll long long
const ll mmod = 998244353;
const ll MMOD = 10e9 + 7;
#define vl vector<long long>
#define vll vector<vector<long long>>
#define pl pair<long long, long long>
#define vb vector<bool>
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n;
cin >> n;
vl ans (n, 0);
ans[0] = 1;
float B = sqrt(n);
ll b = B;
vll skoky (n, vl (b, 0ll));
for (ll i = 0; i < n; i++){
ll d,x;
cin >> d >> x;
ll s = 0;
for (ll j = 0; j < skoky[i].size(); j++){
s += skoky[i][j];
}
ans[i] += s%MMOD;
for (ll j = 0; j < skoky[i].size(); j++){
if (i + j +1< n){
skoky[i+j+1][j] += skoky[i][j];
}
else{
break;
}
}
if (d >= b){
for (ll j = 1; j <= x && j*d + i< n; j++){
ans[j*d + i] += ans[i];
ans[j*d + 1] = ans[j*d+1]%MMOD;
}
}
else{
if (d != 0){
if (i + (x+1)*d < n){
skoky[i + (x+1)*d][d-1] -= ans[i] % MMOD;
}
if (i + d < n){
skoky[i+d][d-1] += ans[i] % MMOD;
}
}
}
}
ll s = 0;
for (ll i = 0; i < ans.size(); i++){
s += ans[i] % MMOD;
}
cout << s % MMOD << "\n";
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... |