# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
513596 | amukkalir | 이상한 기계 (APIO19_strange_device) | C++17 | 1079 ms | 41320 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int n, a, b;
signed main () {
scanf("%d %d %d", &n, &a, &b);
vector<pll> v;
for(int i=0; i<n; i++) {
ll l, r; scanf("%lld %lld", &l, &r);
v.pb(mp(l,r));
}
ull ans = 0;
//if r max < a*b / gcd(a, b+1)
if(v.back().se / b < a / gcd(a, b+1)) {
for(int i=0; i<n; i++) {
ans += v[i].se - v[i].fi + 1;
}
} else {
ll c = a/gcd(a, b+1) * b;
for(int i=0; i<n; i++) {
if(v[i].se % c < v[i].fi % c || v[i].se >= v[i].fi + c) {
v.pb(mp(0, v[i].se % c));
v[i].se = c-1;
}
v[i].fi %= c;
v[i].se %= c;
}
cerr << c << endl;
sort(v.begin(), v.end(), [&] (pll a, pll b) {
if(a.fi % c == b.fi % c) return a.se % c < b.se % c;
return a.fi % c < b.fi % c;
});
//(auto p : v) cout << p.fi << " " << p.se << endl;
for(int i=0; i<v.size(); i++) {
int l = i, r = i;
ll vl = v[i].fi, vr = v[i].se;
while(r + 1 < v.size() && v[r+1].fi <= vr) {
vr = max(vr, v[r+1].se);
//cout << " :: " << vl << " " << vr << endl;
r++;
}
ans += vr - vl + 1;
i = r;
}
}
printf("%llu", ans);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |