Submission #999302

#TimeUsernameProblemLanguageResultExecution timeMemory
999302hengliaoTrains (BOI24_trains)C++17
100 / 100
145 ms7764 KiB
#include<bits/stdc++.h> #include <chrono> #include <random> using namespace std; #define F first #define S second #define pb push_back #define vll vector<ll> #define pll pair<ll, ll> typedef long long ll; const ll mxN=1e5+5; const ll A=300; ll dv[A][A]; ll n; ll dp[mxN]; ll d[mxN], x[mxN]; vll ot[mxN]; const ll mod=1e9+7; void solve(){ memset(dp, 0, sizeof(dp)); memset(dv, 0, sizeof(dv)); cin>>n; for(ll i=0;i<n;i++){ cin>>d[i]>>x[i]; } ll ans=0; dp[0]=1; for(ll i=0;i<n;i++){ for(auto &it:ot[i]){ dv[d[it]][it%d[it]]-=dp[it]; dv[d[it]][it%d[it]]%=mod; if(dv[d[it]][it%d[it]]<0) dv[d[it]][it%d[it]]+=mod; } //cout<<i<<' '<<dp[i]<<'\n'; for(ll j=1;j<A;j++){ dp[i]+=dv[j][i%j]; dp[i]%=mod; } ans+=dp[i]; //cout<<i<<' '<<dp[i]<<'\n'; ans%=mod; if(d[i]==0) continue; if(d[i]>=A){ for(ll j=1;j<=x[i];j++){ if(i+d[i]*j>=n) break; dp[i+d[i]*j]+=dp[i]; dp[i+d[i]*j]%=mod; } } else{ dv[d[i]][i%d[i]]+=dp[i]; dv[d[i]][i%d[i]]%=mod; if(i+d[i]*x[i]+1<n) ot[i+d[i]*x[i]+1].pb(i); } } cout<<ans<<'\n'; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); solve(); return 0; }
#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...