Submission #995503

#TimeUsernameProblemLanguageResultExecution timeMemory
99550312345678Trains (BOI24_trains)C++17
100 / 100
122 ms5712 KiB
#include <bits/stdc++.h> using namespace std; const int nx=1e5+5, mod=1e9+7, kx=255; int n, d[nx], x[nx], qs[kx][kx], dp[nx], res, k=250; vector<int> rem[nx]; void add(int idx) { if (d[idx]==0||x[idx]==0) return; if (d[idx]>k) { for (int i=idx+d[idx], j=0; j<x[idx]&&i<=n; j++, i+=d[idx]) dp[i]=(dp[i]+dp[idx])%mod; } else { qs[d[idx]][idx%d[idx]]=(qs[d[idx]][idx%d[idx]]+dp[idx])%mod; if (idx+((long long)x[idx])*d[idx]<=n) rem[idx+((long long)x[idx])*d[idx]].push_back(idx); } } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n; for (int i=1; i<=n; i++) cin>>d[i]>>x[i]; dp[1]=1; add(1); for (int i=2; i<=n; i++) { for (int j=1; j<=k; j++) dp[i]=(dp[i]+qs[j][i%j])%mod; add(i); for (auto idx:rem[i]) qs[d[idx]][i%d[idx]]=((qs[d[idx]][i%d[idx]]-dp[idx])%mod+mod)%mod; } for (int i=1; i<=n; i++) res=(res+dp[i])%mod; cout<<res; }
#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...