제출 #1123365

#제출 시각아이디문제언어결과실행 시간메모리
1123365PwoTrains (BOI24_trains)C++17
37 / 100
453 ms4544 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int m = 1e9 + 7; int n, dp[100005]; pair<int, int> a[100005]; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; int32_t main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second; dp[1] = 1; if (n <= 10000) { for (int i = 2; i <= n; i++) { for (int j = 1; j < i; j++) { if (a[j].first == 0) continue; int d = i - j; if (d % a[j].first == 0 && (d / a[j].first) <= a[j].second) dp[i] = (dp[i] + dp[j]) % m; } } } else { int sum = 1; pq.emplace(a[1].second + 1, 1); for (int i = 2; i <= n; i++) { while (!pq.empty() && pq.top().first < i) { sum = (sum + m - pq.top().second) % m; pq.pop(); } dp[i] = sum; sum = (sum + dp[i]) % m; pq.emplace(i + a[i].second, dp[i]); } } int ans = 0; for (int i = 1; i <= n; i++) ans = (ans + dp[i]) % m; cout << ans; }
#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...