제출 #258119

#제출 시각아이디문제언어결과실행 시간메모리
258119amoo_safarStrange Device (APIO19_strange_device)C++14
35 / 100
601 ms53568 KiB
// Zende bad Shoma nasime faghat ! #include <bits/stdc++.h> #define pb push_back #define F first #define S second #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " : " << x << '\n' using namespace std; typedef long long ll; typedef long double ld; typedef string str; typedef pair<ll, ll> pll; const ll Mod = 1000000007LL; const int N = 2e5 + 10; const ll Inf = 2242545357980376863LL; const ll Log = 30; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, A, B; cin >> n >> A >> B; ll z = A / __gcd(A, B + 1); ll L = z * B; vector<pll> V; ll l, r; for(int i = 0; i < n; i++){ cin >> l >> r; if(r - l + 1 >= L) return cout << L << '\n', 0; if(l % L <= r % L) V.pb({l % L, r % L}); else { V.pb({l % L, L - 1}); V.pb({0, r % L}); } } sort(all(V)); ll ans = L; ll la = -1; for(auto x : V){ ans -= max(0ll, x.F - la - 1); la = max(la, x.S); } ans -= max(0ll, L - la - 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...