제출 #1033609

#제출 시각아이디문제언어결과실행 시간메모리
1033609KhoaDuyTrains (BOI24_trains)C++14
100 / 100
249 ms251704 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define endl '\n' const int mod=1e9+7; const int MAXN=1e5; const int block=317; int sum[MAXN+1][block+1]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); memset(sum,0,sizeof(sum)); int n; cin >> n; int DP[n+1]; int x[n+1]; int d[n+1]; for(int i=1;i<=n;i++){ cin >> d[i] >> x[i]; } for(int i=n;i>=1;i--){ DP[i]=1; if(d[i]){ if(d[i]>block){ for(int j=i+d[i];j<=min(n,i+x[i]*d[i]);j+=d[i]){ DP[i]+=DP[j]; DP[i]%=mod; } } else{ if(i+d[i]<=n){ int curr=sum[i+d[i]][d[i]]; int minu=0; if((i+(x[i]+1)*d[i])<=n){ minu=sum[i+(x[i]+1)*d[i]][d[i]]; } curr=(curr-minu+mod)%mod; DP[i]+=curr; DP[i]%=mod; } } } for(int j=1;j<=block;j++){ sum[i][j]=DP[i]; if(i+j<=n){ sum[i][j]+=sum[i+j][j]; sum[i][j]%=mod; } } } cout << DP[1]; }
#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...