# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1033601 | don_ban_tinh | Trains (BOI24_trains) | C++14 | 2098 ms | 2260 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 <iostream>
#include <vector>
#include <queue>
#include <cstdio>
using namespace std;
const int MOD = 1000000007;
int main() {
int N;
scanf("%d", &N);
vector<pair<int, int>> routes(N + 1);
for (int i = 1; i <= N; ++i) {
int d, x;
scanf("%d%d", &d, &x);
routes[i] = {d, x};
}
vector<bool> visited(N + 1, false);
vector<long long> dp(N + 1, 0);
dp[1] = 1;
queue<int> q;
q.push(1);
visited[1] = true;
while (!q.empty()) {
int city = q.front();
q.pop();
int d = routes[city].first;
int x = routes[city].second;
if (d > 0) {
for (int t = 1; t <= x; ++t) {
int next_city = city + t * d;
if (next_city <= N) {
if (!visited[next_city]) {
q.push(next_city);
visited[next_city] = true;
}
dp[next_city] = (dp[next_city] + dp[city]) % MOD;
} else {
break;
}
}
}
}
long long result = 0;
for (int i = 1; i <= N; ++i) {
result = (result + dp[i]) % MOD;
}
printf("%lld", result);
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... |