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;
int main() {
long long N;
cin >> N;
if (N == 1) {
cout << 1;
return 0;
}
long long d[N];
long long x[N];
for (long long i = 0; i < N; i++) {
cin >> d[i] >> x[i];
}
bool all = true;
for (int i: d) if (i != 1) all = false;
if (!all) {
long long total[N];
memset(total, 0, sizeof(total));
total[0] = 1;
for (long long i = 0; i < N; i++) {
if (d[i] == 0) continue;
for (long long j = 1; j <= x[i]; j++) {
if (i+j*d[i] >= N) break;
total[i+j*d[i]] += total[i];
total[i+j*d[i]] %= 1000000007;
}
}
long long ans = 0;
for (long long i: total) ans += i;
ans %= 1000000007;
cout << ans;
return 0;
}
long long diff[N];
memset(diff, 0, sizeof(diff));
diff[0] = 1;
diff[1] = -1;
long long dsum = 0;
for (int i = 0; i < N-1; i++) {
dsum += diff[i];
if (dsum < 0) dsum += 1000000007;
dsum %= 1000000007;
diff[i+1] += dsum;
if (diff[i+1] < 0) dsum += 1000000007;
diff[i+1] %= 1000000007;
if (i+1+x[i] < N) {
diff[i+1+x[i]] -= dsum;
if (diff[i+1+x[i]] < 0) dsum += 1000000007;
diff[i+1+x[i]]%=1000000007;
}
}
long long sum[N];
sum[0] = 1;
for (int i = 1; i < N; i++) {
sum[i] = sum[i-1]+diff[i];
if (sum[i] < 0) sum[i] += 1000000007;
sum[i]%=1000000007;
}
long long ans = 0;
for (long long i: sum) {
ans += i;
ans %= 1000000007;
}
cout << ans;
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... |