Submission #994689

#TimeUsernameProblemLanguageResultExecution timeMemory
994689LCJLYTrains (BOI24_trains)C++14
100 / 100
235 ms78932 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define show(x,y) cout << y << " " << #x << endl; #define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl; #define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl; #define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl; typedef pair<int,int>pii; typedef pair<int,pii>pi2; const int blk=300; const int mod=1e9+7; void solve(){ int n; cin >> n; int temp,temp2; vector<int>adj[n+5]; int cnt[305][305]; memset(cnt,0,sizeof(cnt)); vector<int>prefix[n+5]; vector<int>done[n+5]; int arr[n+5]; for(int x=1;x<=n;x++){ cin >> temp >> temp2; arr[x]=temp; if(temp==0) continue; if(temp>=blk){ for(int y=x+temp;y<=n;y+=temp){ if(temp2==0) break; temp2--; adj[x].push_back(y); } } else{ int hold=(n-x)/temp; temp2=min(temp2,hold); prefix[x].push_back(temp); prefix[x+temp2*temp].push_back(-x); } } int dp[n+5]; memset(dp,0,sizeof(dp)); dp[1]=1; for(int x=1;x<=n;x++){ //show(x,x); for(int y=1;y<blk;y++){ dp[x]=(dp[x]+cnt[x%y][y]+mod)%mod; } for(auto it:adj[x]){ dp[it]=(dp[it]+dp[x])%mod; } for(auto it:prefix[x]){ if(it>0){ //show(it,it); cnt[x%it][it]+=dp[x]; cnt[x%it][it]%=mod; } else{ int hold=-it; //show(hold,hold); cnt[hold%arr[hold]][arr[hold]]-=dp[hold]-mod; cnt[hold%arr[hold]][arr[hold]]%=mod; } } //show4(dp,dp); } //show4(dp,dp); int counter=0; for(int x=1;x<=n;x++){ counter=(counter+dp[x])%mod; } cout << counter; } int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); int t=1; //cin >> t; //freopen("in.txt","r",stdin); while(t--){ solve(); } }
#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...