Submission #1123487

#TimeUsernameProblemLanguageResultExecution timeMemory
1123487PwoTrains (BOI24_trains)C++17
71 / 100
486 ms10176 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; unordered_map<int, int> rem[100005]; 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; bool b = 1; for (int i = 1; i <= n; i++) if (a[i].first != 1) b = 0; 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 if (b) { 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]); } } else { vector<int> v; unordered_map<int, int> tmp; for (int i = 1; i <= n; i++) { if (tmp.find(a[i].first) == tmp.end()) { tmp[a[i].first] = v.size(); v.push_back(a[i].first); } } rem[0][1 % a[1].first] = 1; for (int i = 2; i <= n; i++) { for (int idx = 0; idx < v.size(); idx++) { int md = v[idx]; int r = i % md; dp[i] = (dp[i] + rem[idx][r]) % m; } int idx = tmp[a[i].first]; int r = i % a[i].first; rem[idx][r] = (rem[idx][r] + dp[i]) % m; } } 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...