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 int MOD = 1e9+7;
const int LIM = 400;
int n;
vector<int> tole[100005];
int dp[100005];
vector<int> events[100005][LIM+5];
int s[LIM+5][LIM+5];
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n;
int d,x;
for(int i=1;i<=n;i++)
{
cin>>d>>x;
if(d==0 || x==0 || i+d>n)
continue;
if(d<=LIM)
{
int ri = i + min((n-i)/d,x)*d;
events[i+d][d].push_back(i);
if(ri+d<=n) events[ri+d][d].push_back(-i);
}
else
{
for(int j=1;j<=x;j++)
{
if(i+j*d>n)
break;
tole[i+j*d].push_back(i);
}
}
}
dp[1]=1;
int rez=1;
for(int i=2;i<=n;i++)
{
for(int j=1;j<=LIM;j++)
{
for(int e:events[i][j])
{
if(e>0)
{
s[j][i%j] = (s[j][i%j] + dp[e])%MOD;
}
else
{
e = -e;
s[j][i%j] = (s[j][i%j] + MOD - dp[e])%MOD;
}
}
dp[i] = (dp[i] + s[j][i%j])%MOD;
}
for(int j:tole[i])
{
dp[i] = (dp[i] + dp[j])%MOD;
}
rez = (rez + dp[i])%MOD;
}
cout<<rez;
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... |