# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1065165 | ttttttttttttth | Trains (BOI24_trains) | C++17 | 2 ms | 348 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;
#define int long long
const long long N = 1e5 + 5;
const long long inf = 1e9;
const long long mod = 1e9 + 7;
const int Block = 27;
int n, d[N], x[N];
int dp[N], f[N][Block + 5];
signed main() {
ios_base :: sync_with_stdio (0);
cin.tie (0);
freopen ("BUS.inp", "r", stdin);
freopen ("BUS.out", "w", stdout);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> d[i] >> x[i];
}
for (int i = n; i >= 1; i--) {
dp[i] = 0;
if (d[i] == 0) {
dp[i] = 1;
}
else if (d[i] > Block) {
for (int j = i + d[i]; j <= min(n, i + d[i] * x[i]); j += d[i]) {
dp[i] = (dp[i] + dp[j]) % mod;
}
dp[i] = (dp[i] + 1) % mod;
}
else {
dp[i] = 1;
dp[i] = (dp[i] + ((i + d[i] <= n) ? (f[i + d[i]][d[i]]) : 0)) % mod;
dp[i] = (dp[i] - ((i + d[i] * (x[i] + 1) <= n) ? (f[(i + d[i] * (x[i] + 1))][d[i]]) : 0) + mod * mod) % mod;
}
for (int j = 0; j <= Block; j++) {
f[i][j] = ((i + j <= n ? f[i + j][j] : 0) + dp[i]) % mod;
}
}
cout << dp[1];
}
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... |