Submission #1026271

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
10262712024-07-17 18:40:57mareksbTrains (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;
}
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#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...