제출 #1315446

#제출 시각아이디문제언어결과실행 시간메모리
1315446juliany2Trains (BOI24_trains)C++20
0 / 100
40 ms60952 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; #define all(x) (x).begin(), (x).end() const int mod = 1e9 + 7; const int N = 1e5 + 7, B = 320; int n; int rem[N][B]; ll dp[N]; vector<int> l[N]; bool used[N]; int main() { cin.tie(0)->sync_with_stdio(0); cin >> n; dp[1] = 1; ll ans = 0; for (int i = 1; i <= n; i++) { ll d, x; cin >> d >> x; if (d >= B && d <= n) { l[i].push_back(d); for (int c = 1; c < x && i + c * d <= n; c++) { l[i + c * d].push_back(d); } } else if (d > 0 && d < B) { rem[i][d] = max(rem[i][d], (int) x); } for (int j = 1; j < B; j++) { if (rem[i][j] > 0 && i + j <= n) { (dp[i + j] += dp[i]) %= mod; rem[i + j][j] = rem[i][j] - 1; } } for (int j : l[i]) { if (i + j <= n && !used[j]) { used[j] = 1; (dp[i + j] += dp[i]) %= mod; } } for (int j : l[i]) { used[j] = 0; } (ans += dp[i]) %= mod; } cout << ans << '\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...