Submission #995292

#TimeUsernameProblemLanguageResultExecution timeMemory
995292PagodePaivaTrains (BOI24_trains)C++17
42 / 100
140 ms2588 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1e5+10; const int B = 500; int n; int d[N], x[N], dp[N]; int pref[B][B]; const int mod = 1e9+7; void calc(int pos){ if(d[pos] == 0) return; int comp = x[pos]; comp = min(comp, (n-pos)/d[pos]); if(comp <= B){ for(int i = 1;i <= comp;i++){ dp[pos] += dp[pos+d[pos]*i]; dp[pos] %= mod; } return; } else{ dp[pos] += pref[d[pos]][pos % d[pos]]; dp[pos] %= mod; return; } } void upd(int pos){ for(int i = 1;i < B;i++){ pref[i][pos % i] += dp[pos]; pref[i][pos % i] %= mod; } return; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> n; for(int i = 1;i <= n;i++){ cin >> d[i] >> x[i]; } for(int i = 1;i <= n;i++){ dp[i] = 1; } for(int i = n;i >= 1;i--){ calc(i); upd(i); } cout << dp[1] << '\n'; 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...