제출 #1290509

#제출 시각아이디문제언어결과실행 시간메모리
1290509ArtTrains (BOI24_trains)C++20
100 / 100
129 ms129624 KiB
// - Art - #include <bits/stdc++.h> #define el cout << '\n' #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define REV(i, b, a) for (int i = (b), _a = (a); i >= _a; --i) #define REP(i, c) for (int i = 0, _c = (c); i < _c; ++i) const int N = 2e5 + 7; const int BLOCKSIZE = 320; const int MOD = 1e9 + 7; using namespace std; int x[N], d[N]; int dp[N], f[N][BLOCKSIZE + 7]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; FOR (i, 1, n) { cin >> d[i] >> x[i]; dp[i] = 1; } REV (i, n, 1) { if (d[i] > BLOCKSIZE) { for (int j = i + d[i]; j <= min(1LL * n, i + 1LL * x[i] * d[i]); j += d[i]) { dp[i] = (dp[i] + dp[j]) % MOD; } } else { if (i + d[i] <= n) { dp[i] = (1LL * dp[i] + f[i + d[i]][d[i]] - f[min(i + 1LL * (x[i] + 1) * d[i], 1LL * n + 1)][d[i]] + MOD) % MOD; } } FOR (j, 1, BLOCKSIZE) { int add = 0; if (i + j <= n) { add = f[i + j][j]; } f[i][j] = (dp[i] + add) % MOD; } } cout << dp[1], el; 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...