답안 #721469

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
721469 2023-04-11T02:07:15 Z Darren0724 이상한 기계 (APIO19_strange_device) C++17
100 / 100
566 ms 18372 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
const int INF=9e18;

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;cin>>t;
    int a,b;cin>>a>>b;
    int m=0;
    int g=__gcd(a,b+1);
    __int128 tmp=(__int128)a*b/g;
    if(tmp>INF){
        m=INF;
    }
    else{
        m=tmp;
    }
    vector<pair<int,int>> v;
    for(int i=0;i<t;i++){
        int l,r;cin>>l>>r;
        if(r-l+1>=m){
            cout<<m<<endl;
            return 0;
        }
        if(r%m<l%m){
            v.push_back({l%m,m-1});
            v.push_back({0,r%m});
        }
        else{
            v.push_back({l%m,r%m});
        }
    }
    sort(all(v));
    int ans=0;
    int l=0;
    for(pair<int,int> p:v){
        p.first=max(p.first,l);
        if(p.second<p.first){
            continue;
        }
        ans+=(p.second-p.first+1);
        l=p.second+1;
    }
    cout<<ans<<endl;


    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 4 ms 600 KB Output is correct
3 Correct 4 ms 600 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 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 600 KB Output is correct
17 Correct 46 ms 2504 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 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 340 KB Output is correct
5 Correct 296 ms 16880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 406 ms 16852 KB Output is correct
3 Correct 381 ms 16904 KB Output is correct
4 Correct 368 ms 16748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 406 ms 16852 KB Output is correct
3 Correct 381 ms 16904 KB Output is correct
4 Correct 368 ms 16748 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 409 ms 16760 KB Output is correct
7 Correct 391 ms 16856 KB Output is correct
8 Correct 411 ms 16812 KB Output is correct
9 Correct 496 ms 16820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 406 ms 16852 KB Output is correct
3 Correct 381 ms 16904 KB Output is correct
4 Correct 368 ms 16748 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 39 ms 2444 KB Output is correct
7 Correct 42 ms 2420 KB Output is correct
8 Correct 40 ms 2492 KB Output is correct
9 Correct 41 ms 2492 KB Output is correct
10 Correct 40 ms 2396 KB Output is correct
11 Correct 43 ms 2476 KB Output is correct
12 Correct 57 ms 2452 KB Output is correct
13 Correct 41 ms 2384 KB Output is correct
14 Correct 42 ms 2528 KB Output is correct
15 Correct 46 ms 2496 KB Output is correct
16 Correct 41 ms 2480 KB Output is correct
17 Correct 42 ms 2512 KB Output is correct
18 Correct 451 ms 16932 KB Output is correct
19 Correct 408 ms 16792 KB Output is correct
20 Correct 448 ms 16812 KB Output is correct
21 Correct 51 ms 2440 KB Output is correct
22 Correct 44 ms 2396 KB Output is correct
23 Correct 136 ms 8580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 57 ms 2496 KB Output is correct
3 Correct 47 ms 2380 KB Output is correct
4 Correct 566 ms 16756 KB Output is correct
5 Correct 42 ms 2512 KB Output is correct
6 Correct 41 ms 2428 KB Output is correct
7 Correct 45 ms 2432 KB Output is correct
8 Correct 62 ms 2436 KB Output is correct
9 Correct 54 ms 2456 KB Output is correct
10 Correct 46 ms 2496 KB Output is correct
11 Correct 57 ms 2388 KB Output is correct
12 Correct 41 ms 2476 KB Output is correct
13 Correct 43 ms 2464 KB Output is correct
14 Correct 453 ms 16808 KB Output is correct
15 Correct 40 ms 2512 KB Output is correct
16 Correct 454 ms 16772 KB Output is correct
17 Correct 488 ms 16860 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 4 ms 600 KB Output is correct
3 Correct 4 ms 600 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 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 600 KB Output is correct
17 Correct 46 ms 2504 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 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 340 KB Output is correct
28 Correct 296 ms 16880 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 406 ms 16852 KB Output is correct
31 Correct 381 ms 16904 KB Output is correct
32 Correct 368 ms 16748 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 409 ms 16760 KB Output is correct
35 Correct 391 ms 16856 KB Output is correct
36 Correct 411 ms 16812 KB Output is correct
37 Correct 496 ms 16820 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 39 ms 2444 KB Output is correct
40 Correct 42 ms 2420 KB Output is correct
41 Correct 40 ms 2492 KB Output is correct
42 Correct 41 ms 2492 KB Output is correct
43 Correct 40 ms 2396 KB Output is correct
44 Correct 43 ms 2476 KB Output is correct
45 Correct 57 ms 2452 KB Output is correct
46 Correct 41 ms 2384 KB Output is correct
47 Correct 42 ms 2528 KB Output is correct
48 Correct 46 ms 2496 KB Output is correct
49 Correct 41 ms 2480 KB Output is correct
50 Correct 42 ms 2512 KB Output is correct
51 Correct 451 ms 16932 KB Output is correct
52 Correct 408 ms 16792 KB Output is correct
53 Correct 448 ms 16812 KB Output is correct
54 Correct 51 ms 2440 KB Output is correct
55 Correct 44 ms 2396 KB Output is correct
56 Correct 136 ms 8580 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 57 ms 2496 KB Output is correct
59 Correct 47 ms 2380 KB Output is correct
60 Correct 566 ms 16756 KB Output is correct
61 Correct 42 ms 2512 KB Output is correct
62 Correct 41 ms 2428 KB Output is correct
63 Correct 45 ms 2432 KB Output is correct
64 Correct 62 ms 2436 KB Output is correct
65 Correct 54 ms 2456 KB Output is correct
66 Correct 46 ms 2496 KB Output is correct
67 Correct 57 ms 2388 KB Output is correct
68 Correct 41 ms 2476 KB Output is correct
69 Correct 43 ms 2464 KB Output is correct
70 Correct 453 ms 16808 KB Output is correct
71 Correct 40 ms 2512 KB Output is correct
72 Correct 454 ms 16772 KB Output is correct
73 Correct 488 ms 16860 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 0 ms 320 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 1 ms 232 KB Output is correct
79 Correct 5 ms 1044 KB Output is correct
80 Correct 515 ms 18372 KB Output is correct
81 Correct 500 ms 18348 KB Output is correct
82 Correct 464 ms 18364 KB Output is correct
83 Correct 451 ms 18324 KB Output is correct
84 Correct 489 ms 18176 KB Output is correct
85 Correct 469 ms 17948 KB Output is correct
86 Correct 163 ms 10120 KB Output is correct
87 Correct 1 ms 320 KB Output is correct