Submission #1033697

#TimeUsernameProblemLanguageResultExecution timeMemory
1033697hehebjp123Trains (BOI24_trains)C++14
100 / 100
268 ms254868 KiB
#include<bits/stdc++.h> #define ll long long #define fi first #define se second #define ii pair<ll,ll> #define iii pair<ii,ll> #define pb push_back using namespace std; const ll N=1e5+9; const ll mod=1e9+7; const ll S=320; ll f[S+2][N],dp[N],i,j,n,x[N],d[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin>>n; for(i=1;i<=n;i++) cin>>d[i]>>x[i]; memset(dp,0,sizeof(dp)); memset(f,0,sizeof(f)); for(i=n;i>0;i--) { if(d[i]>=S) { for(j=i+d[i];j<=n;j+=d[i]) if((j-i)/d[i]<=x[i]) dp[i]+=dp[j]; } else { dp[i]+=f[d[i]][i]; if(i+(x[i]+1)*d[i]<=n) dp[i]-=f[d[i]][i+(x[i]+1)*d[i]]; } dp[i]=(dp[i]+mod+1)%mod; for(j=1;j<=S;j++) { f[j][i]=(f[j][i]+dp[i])%mod; if(i>j) f[j][i-j]=(f[j][i-j]+f[j][i])%mod; } } cout<<dp[1]; } /* 5 1 3 2 1 1 3 0 10 3 5 */
#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...