Submission #1033668

#TimeUsernameProblemLanguageResultExecution timeMemory
1033668pdaoTrains (BOI24_trains)C++17
8 / 100
2093 ms1048576 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...