Submission #1000877

#TimeUsernameProblemLanguageResultExecution timeMemory
1000877SzilTrains (BOI24_trains)C++17
100 / 100
201 ms315816 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAXN = 100'001; const int K = 400; const ll MOD = 1e9+7; ll dp[MAXN]; ll cnt[MAXN][K]; ll d[MAXN], x[MAXN]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> d[i] >> x[i]; } for (int i = n; i >= 1; i--) { if (d[i] >= K) { dp[i] = 1; for (ll j = i+d[i]; d[i] != 0 && j <= n && j <= i+d[i]*x[i]; j+=d[i]) { dp[i] += dp[j]; dp[i] %= MOD; } dp[i] %= MOD; } else { dp[i] = 1; if (d[i] != 0) { if (i + d[i] <= n) dp[i] += cnt[i + d[i]][d[i]]; if (i + d[i] * (x[i] + 1) <= n) dp[i] -= cnt[i + d[i] * (x[i] + 1)][d[i]]; dp[i] %= MOD; } } for (int j = 1; j < K; j++) { cnt[i][j] = dp[i]; if (i + j <= n) cnt[i][j] += cnt[i+j][j]; cnt[i][j] %= MOD; } } cout << (dp[1] + MOD) % MOD << "\n"; 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...