Submission #997896

#TimeUsernameProblemLanguageResultExecution timeMemory
997896imarnTrains (BOI24_trains)C++14
100 / 100
437 ms9808 KiB
#include<bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("avx2") #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define plx pair<ll,int> #define f first #define s second #define pb push_back #define all(x) x.begin(),x.end() using namespace std; const int blc=351,inf=1e9+7; ll sum[351][351]{0}; priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>pq[blc][blc]; int main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n;cin>>n;pll g[n+1];ll dp[n]={0};dp[0]=1; for(int i=0;i<n;i++)cin>>g[i].f>>g[i].s;ll ans=0; for(int i=0;i<n;i++){ for(int j=1;j<blc;j++){ while(!pq[i%j][j].empty()&&pq[i%j][j].top().f<i)sum[i%j][j]-=pq[i%j][j].top().s,pq[i%j][j].pop(),sum[i%j][j]%=inf; } for(int j=1;j<blc;j++){ dp[i]+=sum[i%j][j];dp[i]%=inf; } if(g[i].f>=blc){int cur=i; for(int j=1;j<=g[i].s;j++){ cur+=g[i].f;if(cur>=n)break; dp[cur]+=dp[i];dp[cur]%=inf; } } else if(g[i].f!=0){ pq[i%g[i].f][g[i].f].push({i+g[i].f*g[i].s,dp[i]}); sum[i%g[i].f][g[i].f]+=dp[i];sum[i%g[i].f][g[i].f]%=inf; } ans+=dp[i];ans%=inf; }cout<<(ans%inf+inf)%inf; }
#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...