# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1003743 | 2024-06-20T16:43:56 Z | underwaterkillerwhale | 이상한 기계 (APIO19_strange_device) | C++17 | 345 ms | 69820 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/__gcd(a, b+1)) * b; 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 | 0 ms | 348 KB | Output is correct |
2 | Correct | 4 ms | 1372 KB | Output is correct |
3 | Correct | 3 ms | 1372 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 440 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 344 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 444 KB | Output is correct |
16 | Correct | 4 ms | 1368 KB | Output is correct |
17 | Correct | 35 ms | 7880 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 356 KB | Output is correct |
2 | Incorrect | 0 ms | 352 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 344 KB | Output is correct |
5 | Correct | 251 ms | 57796 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 290 ms | 69560 KB | Output is correct |
3 | Correct | 300 ms | 69564 KB | Output is correct |
4 | Correct | 280 ms | 69712 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 290 ms | 69560 KB | Output is correct |
3 | Correct | 300 ms | 69564 KB | Output is correct |
4 | Correct | 280 ms | 69712 KB | Output is correct |
5 | Correct | 0 ms | 344 KB | Output is correct |
6 | Correct | 309 ms | 69692 KB | Output is correct |
7 | Correct | 285 ms | 69564 KB | Output is correct |
8 | Correct | 289 ms | 69820 KB | Output is correct |
9 | Correct | 343 ms | 69560 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 290 ms | 69560 KB | Output is correct |
3 | Correct | 300 ms | 69564 KB | Output is correct |
4 | Correct | 280 ms | 69712 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 28 ms | 7660 KB | Output is correct |
7 | Correct | 30 ms | 7808 KB | Output is correct |
8 | Correct | 28 ms | 7880 KB | Output is correct |
9 | Correct | 31 ms | 7900 KB | Output is correct |
10 | Correct | 28 ms | 7880 KB | Output is correct |
11 | Correct | 29 ms | 7656 KB | Output is correct |
12 | Correct | 28 ms | 7888 KB | Output is correct |
13 | Correct | 31 ms | 7732 KB | Output is correct |
14 | Correct | 27 ms | 7704 KB | Output is correct |
15 | Correct | 33 ms | 7880 KB | Output is correct |
16 | Correct | 31 ms | 7888 KB | Output is correct |
17 | Correct | 29 ms | 7696 KB | Output is correct |
18 | Correct | 272 ms | 69560 KB | Output is correct |
19 | Correct | 293 ms | 69604 KB | Output is correct |
20 | Correct | 329 ms | 69596 KB | Output is correct |
21 | Correct | 34 ms | 7876 KB | Output is correct |
22 | Correct | 27 ms | 7884 KB | Output is correct |
23 | Correct | 87 ms | 26496 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 596 KB | Output is correct |
2 | Correct | 31 ms | 7880 KB | Output is correct |
3 | Correct | 32 ms | 7848 KB | Output is correct |
4 | Correct | 303 ms | 69684 KB | Output is correct |
5 | Correct | 30 ms | 7888 KB | Output is correct |
6 | Correct | 34 ms | 7848 KB | Output is correct |
7 | Correct | 31 ms | 7876 KB | Output is correct |
8 | Correct | 32 ms | 7684 KB | Output is correct |
9 | Correct | 30 ms | 7888 KB | Output is correct |
10 | Correct | 31 ms | 7660 KB | Output is correct |
11 | Correct | 31 ms | 7884 KB | Output is correct |
12 | Correct | 28 ms | 7900 KB | Output is correct |
13 | Correct | 31 ms | 7880 KB | Output is correct |
14 | Correct | 331 ms | 69596 KB | Output is correct |
15 | Correct | 59 ms | 7876 KB | Output is correct |
16 | Correct | 345 ms | 69600 KB | Output is correct |
17 | Correct | 288 ms | 69672 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 4 ms | 1372 KB | Output is correct |
3 | Correct | 3 ms | 1372 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 440 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 344 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 444 KB | Output is correct |
16 | Correct | 4 ms | 1368 KB | Output is correct |
17 | Correct | 35 ms | 7880 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 356 KB | Output is correct |
20 | Incorrect | 0 ms | 352 KB | Output isn't correct |
21 | Halted | 0 ms | 0 KB | - |