Submission #1065166

#TimeUsernameProblemLanguageResultExecution timeMemory
1065166ttttttttttttthTrains (BOI24_trains)C++17
100 / 100
182 ms29580 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const long long N = 1e5 + 5; const long long inf = 1e9; const long long mod = 1e9 + 7; const int Block = 27; int n, d[N], x[N]; int dp[N], f[N][Block + 5]; signed main() { ios_base :: sync_with_stdio (0); cin.tie (0); cin >> n; for (int i = 1; i <= n; i++) { cin >> d[i] >> x[i]; } for (int i = n; i >= 1; i--) { dp[i] = 0; if (d[i] == 0) { dp[i] = 1; } else if (d[i] > Block) { for (int j = i + d[i]; j <= min(n, i + d[i] * x[i]); j += d[i]) { dp[i] = (dp[i] + dp[j]) % mod; } dp[i] = (dp[i] + 1) % mod; } else { dp[i] = 1; dp[i] = (dp[i] + ((i + d[i] <= n) ? (f[i + d[i]][d[i]]) : 0)) % mod; dp[i] = (dp[i] - ((i + d[i] * (x[i] + 1) <= n) ? (f[(i + d[i] * (x[i] + 1))][d[i]]) : 0) + mod * mod) % mod; } for (int j = 0; j <= Block; j++) { f[i][j] = ((i + j <= n ? f[i + j][j] : 0) + dp[i]) % mod; } } cout << dp[1]; }
#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...