# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
531648 | 2022-03-01T07:56:40 Z | 79brue | 이상한 기계 (APIO19_strange_device) | C++14 | 546 ms | 69624 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n; ll a, b; ll l[1000002], r[1000002]; int main(){ scanf("%d %lld %lld", &n, &a, &b); for(int i=1; i<=n; i++) scanf("%lld %lld", &l[i], &r[i]); if(1000000000000000000LL / a + 1 <= b){ ll ans = 0; for(int i=1; i<=n; i++) ans += r[i] - l[i] + 1; printf("%lld", ans); return 0; } a = a*b; for(int i=1; i<=n; i++){ if(r[i] - l[i] >= a-1){ printf("%lld", a); return 0; } } vector<pair<ll, ll> > vec; for(int i=1; i<=n; i++){ if(l[i]%a <= r[i]%a) vec.push_back(make_pair(l[i]%a, r[i]%a)); else{ vec.push_back(make_pair(0, r[i]%a)); vec.push_back(make_pair(l[i]%a, a-1)); } } sort(vec.begin(), vec.end()); ll ans = 0; ll rMax = vec[0].second; ll lPnt = vec[0].first; for(int i=0; i<(int)vec.size(); i++){ rMax = max(rMax, vec[i].second); if(i<(int)vec.size()-1 && rMax < vec[i+1].first){ ans += rMax - lPnt + 1; lPnt = vec[i+1].first; } else if(i==(int)vec.size()-1){ ans += rMax - lPnt + 1; } else{ rMax = max(rMax, vec[i].second); } } printf("%lld", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 5 ms | 844 KB | Output is correct |
3 | Correct | 6 ms | 1204 KB | Output is correct |
4 | Incorrect | 1 ms | 204 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 312 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 333 ms | 57616 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 458 ms | 32500 KB | Output is correct |
3 | Incorrect | 472 ms | 69624 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 458 ms | 32500 KB | Output is correct |
3 | Incorrect | 472 ms | 69624 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 458 ms | 32500 KB | Output is correct |
3 | Incorrect | 472 ms | 69624 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 47 ms | 4024 KB | Output is correct |
3 | Correct | 61 ms | 7684 KB | Output is correct |
4 | Correct | 546 ms | 69624 KB | Output is correct |
5 | Correct | 49 ms | 7736 KB | Output is correct |
6 | Correct | 50 ms | 7712 KB | Output is correct |
7 | Correct | 49 ms | 7736 KB | Output is correct |
8 | Correct | 52 ms | 7768 KB | Output is correct |
9 | Correct | 50 ms | 7736 KB | Output is correct |
10 | Correct | 46 ms | 7684 KB | Output is correct |
11 | Correct | 51 ms | 7676 KB | Output is correct |
12 | Correct | 55 ms | 7756 KB | Output is correct |
13 | Correct | 49 ms | 7652 KB | Output is correct |
14 | Correct | 521 ms | 69588 KB | Output is correct |
15 | Incorrect | 58 ms | 7712 KB | Output isn't correct |
16 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 5 ms | 844 KB | Output is correct |
3 | Correct | 6 ms | 1204 KB | Output is correct |
4 | Incorrect | 1 ms | 204 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |