# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1097173 | manhlinh1501 | Trains (BOI24_trains) | C++17 | 261 ms | 292692 KiB |
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;
using i64 = long long;
const int MAXN = 1e5 + 5;
using pii = pair<int, int>;
const i64 MOD = 1e9 + 7;
const int BLOCK = 370;
int N;
pii a[MAXN];
i64 dp[MAXN];
i64 b[BLOCK][MAXN];
void add(i64 &a, i64 b) {
a += b;
if(a >= MOD) a -= MOD;
if(a < 0) a += MOD;
}
namespace subtask {
void solution() {
dp[1] = 1;
for(int i = 1; i <= N; i++) {
if(a[i].first == 0) continue;
for(int j = 1; j <= a[i].second and i + j * a[i].first <= N; j++) {
if(i + j * a[i].first <= N) {
dp[i + j * a[i].first] += dp[i];
dp[i + j * a[i].first] %= MOD;
}
}
}
i64 ans = 0;
for(int i = 1; i <= N; i++) {
ans += dp[i];
ans %= MOD;
}
cout << ans << "\n";
}
}
signed main() {
#define TASK ""
if(fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N;
for(int i = 1; i <= N; i++) cin >> a[i].first >> a[i].second;
for(int i = 1; i <= N; i++) {
if(a[i].first == 0) continue;
a[i].second = min(a[i].second, (N - i) / a[i].first);
}
dp[1] = 1;
for(int i = 1; i <= N; i++) {
for(int j = 0; j < BLOCK; j++)
add(b[j][i], b[j][i - 1]);
for(int j = 0; j < BLOCK; j++)
add(dp[i], b[j][i]);
if(a[i].first == 0) continue;
if(a[i].first > BLOCK) {
for(int j = 1; j <= a[i].second; j++)
add(dp[i + j * a[i].first], dp[i]);
} else {
add(b[i % a[i].first][i + a[i].first], dp[i]);
add(b[i % a[i].first][i + a[i].first * a[i].second + 1], -dp[i]);
}
}
i64 ans = 0;
for(int i = 1; i <= N; i++) add(ans, dp[i]);
cout << ans;
}
Compilation message (stderr)
# | 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... |