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;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pf push_front
#define fi first
#define se second
const ll mod = 1e9+7, mxn = 1e5+7, block = 320;
ll d[mxn], x[mxn], pfs[mxn][block+7], dp[mxn];
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
ll n, ans = 0; cin >> n; dp[1] = 1;
for (ll i = 1; i <= n; i++)
{
for (ll j = 1; j <= block; j++)
{
if (i >= j)
{
pfs[i][j] += pfs[i-j][j];
if (pfs[i][j] >= mod) pfs[i][j] -= mod;
}
dp[i] += pfs[i][j];
if (dp[i] >= mod) dp[i] -= mod;
}
cin >> d[i] >> x[i];
if (!d[i]) continue;
if (d[i] > block)
{
for (ll j = i+d[i]; j <= min(n, i+x[i]*d[i]); j += d[i])
{
dp[j] += dp[i];
if (dp[j] >= mod) dp[j] -= mod;
}
}
else
{
if (i+d[i] > n) continue;
pfs[i+d[i]][d[i]] += dp[i];
if (pfs[i+d[i]][d[i]] >= mod) pfs[i+d[i]][d[i]] -= mod;
if (i+(x[i]+1)*d[i] <= n)
{
pfs[i+(x[i]+1)*d[i]][d[i]] -= dp[i];
if (pfs[i+(x[i]+1)*d[i]][d[i]] < 0) pfs[i+(x[i]+1)*d[i]][d[i]] += mod;
}
}
}
for (ll i = 1; i <= n; i++)
{
ans += dp[i];
if (ans >= mod) ans -= mod;
}
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... |