제출 #1026271

#제출 시각아이디문제언어결과실행 시간메모리
1026271mareksbTrains (BOI24_trains)C++17
100 / 100
192 ms259068 KiB
#include <bits/stdc++.h> using namespace std; constexpr int64_t N = 1e5+5; constexpr int64_t mod = 1e9+7; int64_t dp[N+5]{};//number of paths starting from i constexpr int64_t d=320; int64_t c[N+5][d+5]{};//sum dp given (start pos, step size) int main() { int64_t n; cin>>n; int64_t a[n+1],b[n+1]; for(int64_t i=1;i<=n;i++){ cin>>a[i]>>b[i]; } for(int64_t i=n;i>0;i--){ dp[i]=1; if(a[i]){ if(a[i]>=d){ for(int64_t j=1;j<=b[i];j++){ int64_t pos=i+j*a[i]; if(pos>n)break; dp[i]=(dp[i]+dp[pos])%mod; } } else{ int64_t fin = min(i+a[i]*b[i],n); dp[i]=(dp[i]+c[i][a[i]]-c[fin][a[i]]+mod)%mod; } } //update c state for(int64_t j=1;j<d;j++){ if(i-j<1)break; c[i-j][j]=(c[i][j]+dp[i])%mod; } } cout<<dp[1]%mod<<' '; }
#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...