Submission #1044588

#TimeUsernameProblemLanguageResultExecution timeMemory
1044588BenmathTrains (BOI24_trains)C++14
100 / 100
345 ms198796 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long int dp[n + 2]; long long int con=250; long long int bo[n + 2][con]; long long int mod = 1e9 + 7; for(int i = 0; i <= n;i++){ dp[i] = 0; for(int j = 0; j < con; j++){ bo[i][j] = 0; } } for(int i = 1; i <= n; i++){ for(int j = 1; j < con; j++){ dp[i] = (dp[i] + bo[i][j])% mod; } if(i == 1){ dp[i] = 1; } long long int d,x; cin >> d >> x; if(d >= con){ long long int to = i + d; long long int i1 = i; long long int limit = i1 + d*x; while(to <= n){ if(to > limit){ break; } dp[to] = (dp[to] + dp[i])%mod; to = to + d; } }else{ bo[i][d] = (bo[i][d] + dp[i])% mod; long long int to = i + (x + 1) * d; if(to <= n){ bo[to][d] = (bo[to][d] - dp[i] + mod)% mod; } } for(int j = 1; j < con; j++){ if((i + j) <= n){ bo[i + j][j] = (bo[i + j][j] + bo[i][j])%mod; } } } long long int sum = 0; for(int i = 1; i <= n; i++){ sum = (sum + dp[i])% mod; } cout << sum; }
#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...