이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |