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>
#define int long long
#define pb push_back
using namespace std;
const int maxn = 1e5 + 5;
vector<vector<int>> child(maxn, vector<int>(0));
int ways[maxn]; // ways[i] is number of way to travel the whole town from i
void dfs(int i) {
if (child[i].empty()) ways[i] = 1;
else {
ways[i] = 0;
for (int x : child[i]) {
dfs(x);
ways[i] += ways[x];
}
ways[i] += 1;
}
}
signed main() {
int n, d, x; cin >> n;
for (int i = 1; i <= n; i++) {
cin >> d >> x;
if (d > 0)
for (int j = 1; j <= x; j++) {
if (i + j * d > n) break;
child[i].pb(i + j * d);
}
}
dfs(1);
cout << ways[1];
}
# | 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... |