답안 #445171

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
445171 2021-07-16T17:40:32 Z benedict0724 이상한 기계 (APIO19_strange_device) C++17
100 / 100
596 ms 59208 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

vector<pair<ll, ll>> v1, v2;

ll gcd(ll x, ll y)
{
    if(y == 0) return x;
    return gcd(y, x%y);
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    ll n, A, B; cin >> n >> A >> B;
    ll T = 1e18, S, G;
    G = gcd(A, B+1); A /= G;
    if(T/A >= B) S = A * B;
    else S = 1e18 + 7;

    //cout << S << "\n";

    for(int i=1;i<=n;i++)
    {
        ll l, r; cin >> l >> r;
        if(r - l + 1 >= S)
        {
            v1.push_back({0, S-1});
            continue;
        }
        l %= S, r %= S;
        if(l <= r) v1.push_back({l, r});
        else
        {
            v1.push_back({l, S-1});
            v1.push_back({0, r});
        }
    }

    sort(v1.begin(), v1.end());

    int m = v1.size();
    if(m == 1) v2.push_back(v1[0]);
    for(ll i=1,s=v1[0].first,e=v1[0].second;i<m;i++)
    {
        if(v1[i].first <= e) e = max(v1[i].second, e);
        else
        {
            v2.push_back({s, e});
            s = v1[i].first;
            e = v1[i].second;
        }

        if(i == m-1)
            v2.push_back({s, e});
    }

    m = v2.size();
    ll ans = 0;
    for(int i=0;i<m;i++)
        ans += v2[i].second - v2[i].first + 1;

    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 6 ms 1232 KB Output is correct
3 Correct 6 ms 1232 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 312 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 6 ms 1224 KB Output is correct
17 Correct 55 ms 8588 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 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 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 375 ms 41188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 520 ms 59168 KB Output is correct
3 Correct 513 ms 59100 KB Output is correct
4 Correct 499 ms 51564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 520 ms 59168 KB Output is correct
3 Correct 513 ms 59100 KB Output is correct
4 Correct 499 ms 51564 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 506 ms 51576 KB Output is correct
7 Correct 509 ms 51600 KB Output is correct
8 Correct 505 ms 51568 KB Output is correct
9 Correct 550 ms 51564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 520 ms 59168 KB Output is correct
3 Correct 513 ms 59100 KB Output is correct
4 Correct 499 ms 51564 KB Output is correct
5 Correct 0 ms 312 KB Output is correct
6 Correct 50 ms 8580 KB Output is correct
7 Correct 54 ms 8608 KB Output is correct
8 Correct 51 ms 8560 KB Output is correct
9 Correct 51 ms 8564 KB Output is correct
10 Correct 52 ms 8608 KB Output is correct
11 Correct 52 ms 8644 KB Output is correct
12 Correct 50 ms 8596 KB Output is correct
13 Correct 59 ms 8632 KB Output is correct
14 Correct 50 ms 8632 KB Output is correct
15 Correct 55 ms 8612 KB Output is correct
16 Correct 54 ms 8636 KB Output is correct
17 Correct 51 ms 8576 KB Output is correct
18 Correct 515 ms 51668 KB Output is correct
19 Correct 500 ms 51568 KB Output is correct
20 Correct 541 ms 51600 KB Output is correct
21 Correct 53 ms 8632 KB Output is correct
22 Correct 49 ms 8712 KB Output is correct
23 Correct 153 ms 18488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 57 ms 8656 KB Output is correct
3 Correct 54 ms 8568 KB Output is correct
4 Correct 596 ms 59208 KB Output is correct
5 Correct 53 ms 8572 KB Output is correct
6 Correct 52 ms 8568 KB Output is correct
7 Correct 53 ms 8540 KB Output is correct
8 Correct 54 ms 8564 KB Output is correct
9 Correct 52 ms 8564 KB Output is correct
10 Correct 53 ms 8592 KB Output is correct
11 Correct 54 ms 8640 KB Output is correct
12 Correct 48 ms 8628 KB Output is correct
13 Correct 53 ms 8636 KB Output is correct
14 Correct 562 ms 59180 KB Output is correct
15 Correct 52 ms 8636 KB Output is correct
16 Correct 505 ms 51732 KB Output is correct
17 Correct 502 ms 51552 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 6 ms 1232 KB Output is correct
3 Correct 6 ms 1232 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 312 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 6 ms 1224 KB Output is correct
17 Correct 55 ms 8588 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 316 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 0 ms 312 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 375 ms 41188 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 520 ms 59168 KB Output is correct
31 Correct 513 ms 59100 KB Output is correct
32 Correct 499 ms 51564 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 506 ms 51576 KB Output is correct
35 Correct 509 ms 51600 KB Output is correct
36 Correct 505 ms 51568 KB Output is correct
37 Correct 550 ms 51564 KB Output is correct
38 Correct 0 ms 312 KB Output is correct
39 Correct 50 ms 8580 KB Output is correct
40 Correct 54 ms 8608 KB Output is correct
41 Correct 51 ms 8560 KB Output is correct
42 Correct 51 ms 8564 KB Output is correct
43 Correct 52 ms 8608 KB Output is correct
44 Correct 52 ms 8644 KB Output is correct
45 Correct 50 ms 8596 KB Output is correct
46 Correct 59 ms 8632 KB Output is correct
47 Correct 50 ms 8632 KB Output is correct
48 Correct 55 ms 8612 KB Output is correct
49 Correct 54 ms 8636 KB Output is correct
50 Correct 51 ms 8576 KB Output is correct
51 Correct 515 ms 51668 KB Output is correct
52 Correct 500 ms 51568 KB Output is correct
53 Correct 541 ms 51600 KB Output is correct
54 Correct 53 ms 8632 KB Output is correct
55 Correct 49 ms 8712 KB Output is correct
56 Correct 153 ms 18488 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 57 ms 8656 KB Output is correct
59 Correct 54 ms 8568 KB Output is correct
60 Correct 596 ms 59208 KB Output is correct
61 Correct 53 ms 8572 KB Output is correct
62 Correct 52 ms 8568 KB Output is correct
63 Correct 53 ms 8540 KB Output is correct
64 Correct 54 ms 8564 KB Output is correct
65 Correct 52 ms 8564 KB Output is correct
66 Correct 53 ms 8592 KB Output is correct
67 Correct 54 ms 8640 KB Output is correct
68 Correct 48 ms 8628 KB Output is correct
69 Correct 53 ms 8636 KB Output is correct
70 Correct 562 ms 59180 KB Output is correct
71 Correct 52 ms 8636 KB Output is correct
72 Correct 505 ms 51732 KB Output is correct
73 Correct 502 ms 51552 KB Output is correct
74 Correct 0 ms 204 KB Output is correct
75 Correct 0 ms 312 KB Output is correct
76 Correct 0 ms 204 KB Output is correct
77 Correct 0 ms 204 KB Output is correct
78 Correct 0 ms 204 KB Output is correct
79 Correct 5 ms 1232 KB Output is correct
80 Correct 577 ms 51536 KB Output is correct
81 Correct 569 ms 51620 KB Output is correct
82 Correct 540 ms 51636 KB Output is correct
83 Correct 539 ms 51600 KB Output is correct
84 Correct 542 ms 51612 KB Output is correct
85 Correct 535 ms 51672 KB Output is correct
86 Correct 151 ms 18376 KB Output is correct
87 Correct 1 ms 204 KB Output is correct