제출 #1123511

#제출 시각아이디문제언어결과실행 시간메모리
1123511PwoTrains (BOI24_trains)C++17
58 / 100
2106 ms290416 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int m = 1e9 + 7; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") int n, dp[100005]; pair<int, int> a[100005]; vector<int> v; unordered_map<int, int> tmp; 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; if (a[1].first == 0 || a[1].second == 0) { cout << 1; return 0; } tmp[a[1].first] = 0; v.push_back(a[1].first); rem[0][1 % a[1].first] = 1; pq.emplace(a[1].second * a[1].first + 1, 1); for (int i = 2; i <= n; i++) { while (!pq.empty() && pq.top().first < i) { int idx = pq.top().second; int k = tmp[a[idx].first]; int r = idx % a[idx].first; rem[k][r] = (rem[k][r] - dp[idx] + m) % m; pq.pop(); } for (size_t j = 0; j < v.size(); j++) { int r = i % v[j]; dp[i] = (dp[i] + rem[j][r]) % m; } if (a[i].first > 0 && a[i].second > 0) { if (tmp.find(a[i].first) == tmp.end()) { tmp[a[i].first] = v.size(); v.push_back(a[i].first); } int idx = tmp[a[i].first]; int r = i % a[i].first; rem[idx][r] = (rem[idx][r] + dp[i]) % m; pq.emplace(a[i].second * a[i].first + i, 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...