답안 #720912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
720912 2023-04-09T18:23:59 Z Username4132 이상한 기계 (APIO19_strange_device) C++14
100 / 100
492 ms 53168 KB
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define F first
#define S second

const int MAXN=1000010;
const ll MX = 1000000000000001000;
int n, cnt=0;
ll a, b, D;
pll arr[2*MAXN];

int main(){
    scanf("%d %lld %lld", &n, &a, &b);
    ll part = a/__gcd(a, b+1);
    D=((b > (MX/part))? MX : part*b);

    forn(i, n){
        ll l, r;
        scanf("%lld %lld", &l, &r); ++r;
        if(r-l>=D){
            printf("%lld\n", D);
            return 0;
        }
        ll L=(l%D), R=(r%D);
        if(L<R) arr[cnt++]={L, R};
        else arr[cnt++]={L, D}, arr[cnt++]={0, R};
    }

    arr[cnt++]={MX, MX};
    sort(arr, arr+cnt);
    ll st=-MX, en = -MX, sum=0;
    forn(i, cnt){
        if(en<=arr[i].F){
            sum+=(en-st);
            st=arr[i].F;
        }
        en = max(en, arr[i].S);
    }
    printf("%lld\n", sum);
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d %lld %lld", &n, &a, &b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         scanf("%lld %lld", &l, &r); ++r;
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 7 ms 724 KB Output is correct
3 Correct 5 ms 716 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 308 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 724 KB Output is correct
17 Correct 44 ms 5448 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 289 ms 41208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 406 ms 17876 KB Output is correct
3 Correct 397 ms 17824 KB Output is correct
4 Correct 367 ms 17868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 406 ms 17876 KB Output is correct
3 Correct 397 ms 17824 KB Output is correct
4 Correct 367 ms 17868 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 368 ms 17868 KB Output is correct
7 Correct 384 ms 17936 KB Output is correct
8 Correct 377 ms 17928 KB Output is correct
9 Correct 411 ms 17896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 406 ms 17876 KB Output is correct
3 Correct 397 ms 17824 KB Output is correct
4 Correct 367 ms 17868 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 42 ms 5660 KB Output is correct
7 Correct 42 ms 5452 KB Output is correct
8 Correct 39 ms 5544 KB Output is correct
9 Correct 39 ms 5452 KB Output is correct
10 Correct 40 ms 5496 KB Output is correct
11 Correct 43 ms 5468 KB Output is correct
12 Correct 39 ms 5460 KB Output is correct
13 Correct 46 ms 5616 KB Output is correct
14 Correct 44 ms 5508 KB Output is correct
15 Correct 50 ms 5564 KB Output is correct
16 Correct 45 ms 5468 KB Output is correct
17 Correct 40 ms 5452 KB Output is correct
18 Correct 385 ms 17780 KB Output is correct
19 Correct 378 ms 17796 KB Output is correct
20 Correct 411 ms 17860 KB Output is correct
21 Correct 45 ms 5500 KB Output is correct
22 Correct 40 ms 5544 KB Output is correct
23 Correct 129 ms 18116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 47 ms 5652 KB Output is correct
3 Correct 48 ms 5560 KB Output is correct
4 Correct 477 ms 48672 KB Output is correct
5 Correct 46 ms 5644 KB Output is correct
6 Correct 45 ms 5692 KB Output is correct
7 Correct 42 ms 5452 KB Output is correct
8 Correct 44 ms 5504 KB Output is correct
9 Correct 45 ms 5560 KB Output is correct
10 Correct 46 ms 5500 KB Output is correct
11 Correct 43 ms 5560 KB Output is correct
12 Correct 39 ms 5488 KB Output is correct
13 Correct 43 ms 5580 KB Output is correct
14 Correct 453 ms 48632 KB Output is correct
15 Correct 43 ms 5452 KB Output is correct
16 Correct 429 ms 48724 KB Output is correct
17 Correct 446 ms 48760 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 7 ms 724 KB Output is correct
3 Correct 5 ms 716 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 308 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 724 KB Output is correct
17 Correct 44 ms 5448 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 312 KB Output is correct
24 Correct 1 ms 312 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 328 KB Output is correct
28 Correct 289 ms 41208 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 406 ms 17876 KB Output is correct
31 Correct 397 ms 17824 KB Output is correct
32 Correct 367 ms 17868 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 368 ms 17868 KB Output is correct
35 Correct 384 ms 17936 KB Output is correct
36 Correct 377 ms 17928 KB Output is correct
37 Correct 411 ms 17896 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 42 ms 5660 KB Output is correct
40 Correct 42 ms 5452 KB Output is correct
41 Correct 39 ms 5544 KB Output is correct
42 Correct 39 ms 5452 KB Output is correct
43 Correct 40 ms 5496 KB Output is correct
44 Correct 43 ms 5468 KB Output is correct
45 Correct 39 ms 5460 KB Output is correct
46 Correct 46 ms 5616 KB Output is correct
47 Correct 44 ms 5508 KB Output is correct
48 Correct 50 ms 5564 KB Output is correct
49 Correct 45 ms 5468 KB Output is correct
50 Correct 40 ms 5452 KB Output is correct
51 Correct 385 ms 17780 KB Output is correct
52 Correct 378 ms 17796 KB Output is correct
53 Correct 411 ms 17860 KB Output is correct
54 Correct 45 ms 5500 KB Output is correct
55 Correct 40 ms 5544 KB Output is correct
56 Correct 129 ms 18116 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 47 ms 5652 KB Output is correct
59 Correct 48 ms 5560 KB Output is correct
60 Correct 477 ms 48672 KB Output is correct
61 Correct 46 ms 5644 KB Output is correct
62 Correct 45 ms 5692 KB Output is correct
63 Correct 42 ms 5452 KB Output is correct
64 Correct 44 ms 5504 KB Output is correct
65 Correct 45 ms 5560 KB Output is correct
66 Correct 46 ms 5500 KB Output is correct
67 Correct 43 ms 5560 KB Output is correct
68 Correct 39 ms 5488 KB Output is correct
69 Correct 43 ms 5580 KB Output is correct
70 Correct 453 ms 48632 KB Output is correct
71 Correct 43 ms 5452 KB Output is correct
72 Correct 429 ms 48724 KB Output is correct
73 Correct 446 ms 48760 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 308 KB Output is correct
76 Correct 1 ms 312 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 1 ms 308 KB Output is correct
79 Correct 4 ms 724 KB Output is correct
80 Correct 481 ms 53128 KB Output is correct
81 Correct 492 ms 53168 KB Output is correct
82 Correct 454 ms 53020 KB Output is correct
83 Correct 470 ms 53076 KB Output is correct
84 Correct 480 ms 52936 KB Output is correct
85 Correct 439 ms 53076 KB Output is correct
86 Correct 130 ms 18112 KB Output is correct
87 Correct 1 ms 212 KB Output is correct