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 <iostream>
#include <vector>
using namespace std;
#define int long long
const int N = 1e5 + 5;
int dp[N], mod = 1e9 + 7, Ans;
int Mod[505][505];
vector<pair<int,int>> rem[N];
signed main(){
int n;
cin>>n;
dp[1] = 1;
for (int i=1, d, x;i<=n;i++){
cin>>d>>x;
for (int m=1;m<=500;m++)
dp[i] = (dp[i] + Mod[m][i % m]) % mod;
if (d > 500){
for (int j=d;j/d<=x and i + j <= n;j+=d)
dp[j + i] = (dp[j + i] + dp[i]) % mod;
}
else if (d){
Mod[d][i % d] = (Mod[d][i % d] + dp[i]) % mod;
}
if (d and d * x + i <= n)
rem[d * x + i].push_back({i, d});
for (auto [ind, d_ind] : rem[i])
Mod[d_ind][ind % d_ind] = (Mod[d_ind][ind % d_ind] - dp[ind] + mod) % mod;
Ans = (Ans + dp[i]) % mod;
// exit by removing those
}
cout<<Ans<<'\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... |