Submission #1124251

#TimeUsernameProblemLanguageResultExecution timeMemory
1124251MateiKing80Trains (BOI24_trains)C++20
100 / 100
315 ms255640 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; #define int ll const int mod = 1e9 + 7; #define fr first #define sc second signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int b = sqrt(n); vector<pair<int, int>> train(n); for(int i = 0; i < n; i ++) { cin >> train[i].fr >> train[i].sc; train[i].fr = min(n + 5, train[i].fr); train[i].sc = min(n + 5, train[i].sc); } vector<int> dp(n + 3, 1); vector<vector<int>> dp2(n + 3, vector<int>(b + 3, 0)); for(int i = n - 1; i >= 0; i --) { if(train[i].fr == 0 || train[i].sc == 0) { for(int j = 1; j <= b; j ++) { if(i + j < n) dp2[i][j] = dp2[i + j][j]; dp2[i][j] += dp[i]; dp2[i][j] %= mod; } continue; } if(train[i].fr >= b) { for(int j = 1; j <= train[i].sc && train[i].fr * j + i < n; j ++) { dp[i] += dp[j * train[i].fr + i]; dp[i] %= mod; } } else { if(i + train[i].fr < n) dp[i] += dp2[i + train[i].fr][train[i].fr]; if(i + train[i].fr * (train[i].sc + 1) < n) dp[i] -= dp2[i + train[i].fr * (train[i].sc + 1)][train[i].fr]; dp[i] %= mod; dp[i] += mod; dp[i] %= mod; } for(int j = 1; j <= b; j ++) { if(i + j < n) dp2[i][j] = dp2[i + j][j]; dp2[i][j] += dp[i]; dp2[i][j] %= mod; } } cout << dp[0]; return 0; }
#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...