제출 #1095474

#제출 시각아이디문제언어결과실행 시간메모리
1095474LaMatematica14Trains (BOI24_trains)C++17
21 / 100
2094 ms3924 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+1, 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]*x[i]+1]; dp[i] %= mod; } } for (int j = 1; j <= min(rad-1, N-i); j++) { pr[j][i] = dp[i]+pr[j][i+j]; pr[j][i] %= mod; } } return dp[0]; } long long solve2(int N, vector<long long> &d, vector<long long> &x) { vector<long long> dp(N, 1); for (int i = N-1; i >= 0; i--) { if (x[i] == 0) continue; int k = 1; for (int j = i+x[i]; j < N; j+=x[i]) { if (k > d[i]) break; dp[i] += dp[j]; dp[i] %= mod; k++; } } 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 << solve2(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...