Submission #1232568

#TimeUsernameProblemLanguageResultExecution timeMemory
1232568asdfgraceTrains (BOI24_trains)C++20
0 / 100
2092 ms1860 KiB
#include <bits/stdc++.h> using namespace std; #define dbg(x) x #define prt(x) dbg(cerr << x) #define pv(x) dbg(cerr << #x << " = " << x << '\n') #define parr(x) dbg(cerr << #x << " = "; for (auto y : x) {cerr << y << ' ';} cerr << '\n';) #define parr2d(x) dbg(cerr << #x << " = \n"; for (auto _ : x) {parr(_);} cerr << '\n';) /* dp[i] = # of unique paths if you get on the train at i it's gonna be the sum of all unique paths of stuff that is a multiple of d[i] after i as long as they are stops if there are less than sqrt(n) stops, you can add all of them if d[i] = 1 you could maintain a single suffix sum if there are more than sqrt(n) stops: ??? there are still o(n) combinations of an interval & a mod, so you can't maintain all of them actually every element only fits o(sqrt(n)) of them so just maintain a running suffix thing of these 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 */ const long long mod = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> d(n), x(n); for (int i = 0; i < n; i++) { cin >> d[i] >> x[i]; } if (*max_element(d.begin(), d.end()) == 1 && *min_element(d.begin(), d.end()) == 1) { int lst = n; for (int i = 0; i < n; i++) { if (x[i] == 0) { lst = i + 1; break; } } cout << lst << '\n'; } else { vector<long long> dp(n, 0); for (int i = n - 1; i >= 0; i--) { dp[i] = 1; if (d[i] == 0) continue; for (int j = i + d[i]; j < n && (j - i) / d[i] <= x[i]; j += d[i]) { dp[i] += dp[j]; dp[i] %= mod; } } cout << dp[0] << '\n'; } }
#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...