제출 #1082954

#제출 시각아이디문제언어결과실행 시간메모리
1082954alexdumitruTrains (BOI24_trains)C++17
100 / 100
182 ms128596 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int NMAX = 1e5; const int LIM = 320; const int MOD = 1e9 + 7; void add(int & x, const int & y) { x += y; x >= MOD && (x -= MOD); } void sub(int & x, const int & y) { x -= y; x < 0 && (x += MOD); } int n; int d[NMAX + 1], x[NMAX + 1]; int dp[NMAX + 1]; int sumdp[NMAX + 1][LIM]; void read() { cin >> n; for (int i = 1; i <= n; i++) { cin >> d[i] >> x[i]; } } void solve() { for (int i = n; i >= 1; i--) { dp[i] = 1; if (d[i] >= LIM) { for (int pos = i + d[i], cnt = 1; pos <= n && cnt <= x[i]; pos += d[i], cnt++) add(dp[i], dp[pos]); } else if (d[i] != 0) { int nr = min(x[i], (n - i) / d[i]) + 1; add(dp[i], sumdp[i + d[i]][d[i]]); if (i + nr * d[i] <= n) sub(dp[i], sumdp[i + nr * d[i]][d[i]]); } for (int m = 1; m < LIM; m++) { sumdp[i][m] = i + m <= n ? sumdp[i + m][m] : 0; add(sumdp[i][m], dp[i]); } } cout << dp[1] << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); read(); 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...