Submission #977104

#TimeUsernameProblemLanguageResultExecution timeMemory
977104akacool445kStrange Device (APIO19_strange_device)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define int long long const long long mod = 1e9 + 7; const long long shrek = (1 << 30); int gcd(int a, int b) { if(a == 0) return b; if(b == 0) return a; return gcd(b % a, a); } signed main() { int A, B, n; cin >> n >> A >> B; int k = gcd(A, B + 1); double fuk = 1.0 * A * B / k; int gay = 1e18; if(fuk <= 1e18) gay = B * A / k; set<pair<int, int>> v; bool cmd = 0; for(int i = 0; i < n; i++) { int x, y; cin >> x >> y; if(y - x + 1 >= gay) { cmd = 1; continue; } else { x = x % gay; y = y % gay; if(x <= y) { v.insert({x, y}); } else { v.insert({0, y}); v.insert({x, gay - 1}); } } } v.insert({2e18, 2e18}); if(cmd == 1) { cout << gay << '\n'; } int ans = 0; int l, r; l = (*v.begin()).ff; r = l; for(auto x : v) { if(r < x.ff) { ans = ans + r - l + 1; l = x.ff; r = x.ss; } r = max(r, x.ss); } 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...