제출 #1095551

#제출 시각아이디문제언어결과실행 시간메모리
1095551LaMatematica14Trains (BOI24_trains)C++17
100 / 100
449 ms252748 KiB
#include <bits/stdc++.h> using namespace std; const long long rad = 316; const long long mod = 1e9+7; long long solve(long long N, vector<long long> &d, vector<long long> &x) { vector<vector<long long>> pr(rad, vector<long long> (N+rad, 0)); vector<long long> dp(N, 1); for (int i = N-1; i >= 0; i--) { if (x[i] >= rad) { for (int k = i+x[i]; k < min(N, i+d[i]*x[i]+1); k+= x[i]) { dp[i] += dp[k]; dp[i] %= mod; } } else { if (d[i] > 0) { dp[i] += pr[x[i]][i+x[i]]-pr[x[i]][i+(d[i]+1)*x[i]]; while (dp[i] < 0) dp[i] += mod; dp[i] %= mod; } } for (int j = 1; j < rad; j++) { if (i+j < N) { pr[j][i] = dp[i]+pr[j][i+j]; pr[j][i] %= mod; } else pr[j][i] = dp[i]; } } return dp[0]; } int main() { long long N; cin >> N; vector<long long> d(N), x(N); for (int i = 0; i < N; i++) cin >> x[i] >> d[i]; for (int i = 0; i < N; i++) { if (x[i] == 0) d[i] = 0; else d[i] = min(d[i], (N-i-1)/x[i]); } cout << (solve(N, d, x)); }
#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...