제출 #283183

#제출 시각아이디문제언어결과실행 시간메모리
283183WLZ이상한 기계 (APIO19_strange_device)C++14
65 / 100
540 ms53568 KiB
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { while (b > 0) { swap(a, b); b %= a; } return a; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; long long a, b; cin >> n >> a >> b; long long md = (long long) 1e18 + 1; a /= gcd(a, b + 1); if (a <= numeric_limits<long long>::max() / b) { md = a * b; } vector< pair<long long, long long> > v; for (int i = 0; i < n; i++) { long long l, r; cin >> l >> r; long long x = l % md, y = r % md; if (x <= y) { v.push_back({x, y}); } else { v.push_back({x, md - 1}); v.push_back({0, y}); } } sort(v.begin(), v.end()); long long ans = 0; long long l = v[0].first, r = v[0].second; for (auto& p : v) { if (p.first > r) { ans += r - l + 1; l = p.first; r = p.second; } else { r = max(r, p.second); } } ans += r - l + 1; 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...