제출 #995315

#제출 시각아이디문제언어결과실행 시간메모리
995315PagodePaivaTrains (BOI24_trains)C++17
42 / 100
83 ms1952 KiB
#include<bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int N = 1e5+10; const int B = sqrt(N); 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]); //cout << pos << ' ' << comp << ' '; if(comp <= B){ for(int i = 1;pos+d[pos]*i <= n and 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...