답안 #229644

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
229644 2020-05-05T14:33:44 Z davooddkareshki 이상한 기계 (APIO19_strange_device) C++17
100 / 100
599 ms 53596 KB
// be name khoda
#include<bits/stdc++.h>

using namespace std;

#define F first
#define S second
//#define mp make_pair 
typedef long long ll;
#define int long long
#pragma GCC optimize("Ofast")

const int maxn = 2e5+10;
const int mod = 1e9+7;
const ll inf = 1e18+10;
//const int N = 2e6+10;

int n, m, A, B;

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    cin>> n >> A >> B;
    m = A / __gcd(A,B+1);
    if(m <= inf/B) m *= B;
    else m = inf;
    bool T = 0;

    vector<pair<int,int>> seg;
    for(int i = 1, l, r; i <= n; i++)
    {
        cin>> l >> r;
        if(r-l+1 >= m) T = 1;
        l %= m; r %= m;
        if(l <= r)
            seg.push_back({l,r});            
        else
        {
            seg.push_back({l,m-1});
            seg.push_back({0,r});
        }
    }
    if(T)
        return cout<< m, 0;
    sort(seg.begin(), seg.end());

    ll ans = 0, mx = -1;
    for(int i = 0; i < seg.size(); i++)
    {
        int l = seg[i].F, r = seg[i].S;
        //cout<< l <<" "<< r <<"\n";
        mx = max(mx,l-1);
        if(r-mx >= 0)
            ans += r-mx;
        mx = max(mx,r);
    }
    cout<< ans;
}
/*
3 3 3
4 4
7 9
17 18

3 5 10
1 20
50 68
89 98

2 16 13
2 5
18 18
*/

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:49:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < seg.size(); i++)
                    ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 9 ms 768 KB Output is correct
3 Correct 10 ms 1152 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 436 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 10 ms 1152 KB Output is correct
17 Correct 61 ms 5740 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 374 ms 41416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 517 ms 17020 KB Output is correct
3 Correct 553 ms 53480 KB Output is correct
4 Correct 536 ms 53452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 517 ms 17020 KB Output is correct
3 Correct 553 ms 53480 KB Output is correct
4 Correct 536 ms 53452 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 528 ms 53444 KB Output is correct
7 Correct 530 ms 53312 KB Output is correct
8 Correct 534 ms 53312 KB Output is correct
9 Correct 561 ms 53448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 517 ms 17020 KB Output is correct
3 Correct 553 ms 53480 KB Output is correct
4 Correct 536 ms 53452 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 55 ms 5740 KB Output is correct
7 Correct 57 ms 5740 KB Output is correct
8 Correct 54 ms 5740 KB Output is correct
9 Correct 54 ms 5736 KB Output is correct
10 Correct 55 ms 5740 KB Output is correct
11 Correct 58 ms 5740 KB Output is correct
12 Correct 53 ms 5740 KB Output is correct
13 Correct 80 ms 5736 KB Output is correct
14 Correct 57 ms 5740 KB Output is correct
15 Correct 82 ms 5872 KB Output is correct
16 Correct 60 ms 5740 KB Output is correct
17 Correct 54 ms 5736 KB Output is correct
18 Correct 531 ms 53444 KB Output is correct
19 Correct 529 ms 53312 KB Output is correct
20 Correct 571 ms 53568 KB Output is correct
21 Correct 58 ms 5740 KB Output is correct
22 Correct 55 ms 5740 KB Output is correct
23 Correct 163 ms 18532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 61 ms 2544 KB Output is correct
3 Correct 60 ms 5736 KB Output is correct
4 Correct 599 ms 53352 KB Output is correct
5 Correct 61 ms 5740 KB Output is correct
6 Correct 60 ms 5736 KB Output is correct
7 Correct 60 ms 5740 KB Output is correct
8 Correct 59 ms 5756 KB Output is correct
9 Correct 56 ms 5740 KB Output is correct
10 Correct 60 ms 5736 KB Output is correct
11 Correct 60 ms 5740 KB Output is correct
12 Correct 54 ms 5780 KB Output is correct
13 Correct 63 ms 5740 KB Output is correct
14 Correct 570 ms 53352 KB Output is correct
15 Correct 59 ms 5736 KB Output is correct
16 Correct 516 ms 53332 KB Output is correct
17 Correct 549 ms 53312 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 9 ms 768 KB Output is correct
3 Correct 10 ms 1152 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 436 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 10 ms 1152 KB Output is correct
17 Correct 61 ms 5740 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 374 ms 41416 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 517 ms 17020 KB Output is correct
31 Correct 553 ms 53480 KB Output is correct
32 Correct 536 ms 53452 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 528 ms 53444 KB Output is correct
35 Correct 530 ms 53312 KB Output is correct
36 Correct 534 ms 53312 KB Output is correct
37 Correct 561 ms 53448 KB Output is correct
38 Correct 4 ms 384 KB Output is correct
39 Correct 55 ms 5740 KB Output is correct
40 Correct 57 ms 5740 KB Output is correct
41 Correct 54 ms 5740 KB Output is correct
42 Correct 54 ms 5736 KB Output is correct
43 Correct 55 ms 5740 KB Output is correct
44 Correct 58 ms 5740 KB Output is correct
45 Correct 53 ms 5740 KB Output is correct
46 Correct 80 ms 5736 KB Output is correct
47 Correct 57 ms 5740 KB Output is correct
48 Correct 82 ms 5872 KB Output is correct
49 Correct 60 ms 5740 KB Output is correct
50 Correct 54 ms 5736 KB Output is correct
51 Correct 531 ms 53444 KB Output is correct
52 Correct 529 ms 53312 KB Output is correct
53 Correct 571 ms 53568 KB Output is correct
54 Correct 58 ms 5740 KB Output is correct
55 Correct 55 ms 5740 KB Output is correct
56 Correct 163 ms 18532 KB Output is correct
57 Correct 4 ms 384 KB Output is correct
58 Correct 61 ms 2544 KB Output is correct
59 Correct 60 ms 5736 KB Output is correct
60 Correct 599 ms 53352 KB Output is correct
61 Correct 61 ms 5740 KB Output is correct
62 Correct 60 ms 5736 KB Output is correct
63 Correct 60 ms 5740 KB Output is correct
64 Correct 59 ms 5756 KB Output is correct
65 Correct 56 ms 5740 KB Output is correct
66 Correct 60 ms 5736 KB Output is correct
67 Correct 60 ms 5740 KB Output is correct
68 Correct 54 ms 5780 KB Output is correct
69 Correct 63 ms 5740 KB Output is correct
70 Correct 570 ms 53352 KB Output is correct
71 Correct 59 ms 5736 KB Output is correct
72 Correct 516 ms 53332 KB Output is correct
73 Correct 549 ms 53312 KB Output is correct
74 Correct 5 ms 384 KB Output is correct
75 Correct 4 ms 384 KB Output is correct
76 Correct 4 ms 384 KB Output is correct
77 Correct 5 ms 384 KB Output is correct
78 Correct 5 ms 384 KB Output is correct
79 Correct 10 ms 1152 KB Output is correct
80 Correct 589 ms 53376 KB Output is correct
81 Correct 578 ms 53312 KB Output is correct
82 Correct 593 ms 53396 KB Output is correct
83 Correct 564 ms 53596 KB Output is correct
84 Correct 563 ms 53376 KB Output is correct
85 Correct 545 ms 53312 KB Output is correct
86 Correct 178 ms 18528 KB Output is correct
87 Correct 5 ms 384 KB Output is correct