제출 #398385

#제출 시각아이디문제언어결과실행 시간메모리
398385jack715이상한 기계 (APIO19_strange_device)C++14
65 / 100
591 ms16928 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define pp pop_back #define mp make_pair #define bb back #define ff first #define ss second #define int long long using namespace std; /* ____ __ _______ _______ __________ | \ | | | _____| / _____) |____ ____| | |\ \ | | | |__ ( (_____ | | | | \ \| | | __| \_____ \ | | | | \ | | |_____ _____) ) | | |__| \____| |_______| (_______/ |__| */ int INF = LLONG_MAX; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, A, B, I, gcd, k, l, r; cin >> n >> A >> B; gcd = __gcd(A, B+1); if (gcd == 1) k = A; else k = A / gcd; if (INF / k <= B) I = INF; else I = k*B; vector<pair<int, int> > rem; for (int i = 0; i < n; i++) { cin >> l >> r; if (r-l >= I) { rem.pb({0, I}); } else if (l%I > r%I) { rem.pb({l%I, I-1}); rem.pb({0, r%I}); } else { rem.pb({l%I, r%I}); } } int L = 0, ans = 0; sort(rem.begin(), rem.end()); for (auto el : rem) { el.ff = max(el.ff, L); if (el.ff > el.ss) continue; ans += el.ss-el.ff+1; L = max(L, el.ss+1); } cout << ans << '\n'; return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */
#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...