Submission #1033930

#TimeUsernameProblemLanguageResultExecution timeMemory
1033930_shr104Trains (BOI24_trains)C++14
100 / 100
207 ms258752 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define pb push_back #define pf push_front #define fi first #define se second const ll mod = 1e9+7, mxn = 1e5+7, block = 320; ll d[mxn], x[mxn], pfs[mxn][block+7], dp[mxn]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr); ll n, ans = 0; cin >> n; dp[1] = 1; for (ll i = 1; i <= n; i++) { for (ll j = 1; j <= block; j++) { if (i >= j) { pfs[i][j] += pfs[i-j][j]; if (pfs[i][j] >= mod) pfs[i][j] -= mod; } dp[i] += pfs[i][j]; if (dp[i] >= mod) dp[i] -= mod; } cin >> d[i] >> x[i]; if (!d[i]) continue; if (d[i] > block) { for (ll j = i+d[i]; j <= min(n, i+x[i]*d[i]); j += d[i]) { dp[j] += dp[i]; if (dp[j] >= mod) dp[j] -= mod; } } else { if (i+d[i] > n) continue; pfs[i+d[i]][d[i]] += dp[i]; if (pfs[i+d[i]][d[i]] >= mod) pfs[i+d[i]][d[i]] -= mod; if (i+(x[i]+1)*d[i] <= n) { pfs[i+(x[i]+1)*d[i]][d[i]] -= dp[i]; if (pfs[i+(x[i]+1)*d[i]][d[i]] < 0) pfs[i+(x[i]+1)*d[i]][d[i]] += mod; } } } for (ll i = 1; i <= n; i++) { ans += dp[i]; if (ans >= mod) ans -= mod; } cout << ans << '\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...