Submission #1112502

#TimeUsernameProblemLanguageResultExecution timeMemory
1112502gelastropodTrains (BOI24_trains)C++14
100 / 100
469 ms254948 KiB
#include <iostream> #include <vector> using namespace std; #define int long long signed main(signed argc, char *argv[]) { int N, d, x; cin >> N; vector<vector<int>> prefs; vector<int> dp(N, 0); for (int i = 0; i * i < N; i++) prefs.push_back(vector<int>(N, 0)); vector<pair<int, int>> vals; for (int i = 0; i < N; i++) { cin >> d >> x; vals.push_back({d, x}); } for (int i = N - 1; i >= 0; i--) { if (vals[i].first == 0) dp[i] = 1; else if ((vals[i].first - 1) * (vals[i].first - 1) < N) { if (i + vals[i].first >= N) dp[i] = 1; else if (i + vals[i].first * (vals[i].second + 1) >= N) dp[i] = 1 + prefs[vals[i].first - 1][i + vals[i].first]; else dp[i] = 1 + prefs[vals[i].first - 1][i + vals[i].first] - prefs[vals[i].first - 1][i + vals[i].first * (vals[i].second + 1)]; } else { dp[i] = 1; for (int j = i + vals[i].first, k = 1; j < N && k <= vals[i].second; j += vals[i].first, k++) dp[i] += dp[j]; } dp[i] %= 1000000007; for (int j = 0; j * j < N; j++) { if (i + j + 1 < N) prefs[j][i] = prefs[j][i + j + 1] + dp[i]; else prefs[j][i] = dp[i]; } } 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...