Submission #1052970

#TimeUsernameProblemLanguageResultExecution timeMemory
1052970Sir_Ahmed_ImranTrains (BOI24_trains)C++17
100 / 100
1761 ms143952 KiB
///~~~LOTA~~~/// #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define append push_back #define add insert #define nl '\n' #define ff first #define ss second #define pii pair<int,int> #define pll pair<ll,ll> #define all(x) (x).begin(),(x).end() #define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define terminator main #define N 100002 const ll M=1e9+7; vector<int> a[N]; map<int,int> x[N]; map<int,int> y[N]; map<int,int> dp[N]; void solve(){ int n,m,o; ll p,q; cin>>n; m=0; for(int i=1;i<=n;i++){ o=(i==1); cin>>p>>q; for(auto& j:a[i]) o=(o+dp[j][i%j])%M; m=(m+o)%M; if(p) q=min((n-i)/p,q); if(p && q && p<n){ y[p][i%p]=max(i,y[p][i%p]); for(int j=y[p][i%p]+p;j<=i+p*q;j+=p) a[j].append(p); y[p][i%p]=max(i+p*q,1ll*y[p][i%p]); dp[p][i%p]=(dp[p][i%p]+o)%M; x[i+p*q][p]=(x[min(1ll*n+1,i+p*q)][p]+o)%M; } for(auto& j:x[i]) dp[j.ff][i%j.ff]=(dp[j.ff][i%j.ff]+M-j.ss)%M; } cout<<m; } int terminator(){ L0TA; 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...