# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1051397 | deera | Trains (BOI24_trains) | C++14 | 291 ms | 398680 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;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
ll n; cin >> n;
ll m = n + 100;
const ll p = 500; // (ll)sqrt(n);
vector<ll> dp(m);
vector<ll> d(m), x(m);
vector<vector<ll>> rest(m, vector<ll>(p, 0));
for (ll i = 1; i <= n; i++) cin >> d[i] >> x[i];
for (ll i = 0; i < dp.size(); i++) dp[i] = 1;
for (ll i = n; i >= 1; i--) {
ll step = d[i];
ll next = i + step;
ll maxd = i + step * (x[i] + 1);
if (d[i] != 0) { // it's not broken
if (step >= p) {
for (ll j = next; j <= n && j <= maxd - x[i]; j+=step) {
dp[i] = (dp[j] + dp[i]) % MOD;
}
} else {
if (next <= n) dp[i] = (dp[i] + rest[next][step]) % MOD;
if (maxd <= n) dp[i] = (dp[i] - rest[maxd][step]) % MOD;
}
}
for (int step = 1; step < p; step++) {
ll next = i + step;
rest[i][step] = dp[i];
if (next > n) continue;
rest[i][step] = (rest[i][step] + rest[next][step]) % MOD;
}
}
cout << dp[1] % MOD << endl;
return 0;
}
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... |