Submission #1173309

#TimeUsernameProblemLanguageResultExecution timeMemory
1173309thinknoexit이상한 기계 (APIO19_strange_device)C++20
100 / 100
504 ms33476 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const ll INF = 1e18 + 2; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; ll A, B; cin >> n >> A >> B; ll one = A / gcd(A, B + 1); if (one >= (INF + B - 1) / B) one = INF; else one *= B; // cout << one << '\n'; vector<pair<ll, int>> sweep; for (int i = 1;i <= n;i++) { ll l, r; cin >> l >> r; if (r - l + 1 >= one) { cout << one << '\n'; return 0; } l %= one, r %= one; // cout << l << ' ' << r << '\n'; if (l <= r) { sweep.push_back({ l, 1 }); sweep.push_back({ r + 1, -1 }); } else { sweep.push_back({ 0, 1 }); sweep.push_back({ r + 1, -1 }); sweep.push_back({ l, 1 }); sweep.push_back({ one, -1 }); } } sort(sweep.begin(), sweep.end()); ll ans = 0; int now = 0; for (int i = 0, j;i < (int)sweep.size();i = j) { for (j = i;j < (int)sweep.size() && sweep[i].first == sweep[j].first; j++) { now += sweep[j].second; } if (now > 0) { ans += sweep[j].first - sweep[i].first; } } 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...