답안 #785882

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
785882 2023-07-17T17:39:16 Z aykhn 이상한 기계 (APIO19_strange_device) C++14
100 / 100
1381 ms 63176 KB
#include <bits/stdc++.h>

// author: aykhn

using namespace std;

typedef long long ll;

#define TC int t; cin >> t; while (t--) _();
#define OPT ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define mpr make_pair
#define eb emplace_back
#define new int32_t
#define pb push_back
#define ts to_string
#define fi first
#define se second
#define int ll
#define ins insert
#define inf 0x3F3F3F3F
#define infll 0x3F3F3F3F3F3F3F3FLL
#define bpc __builtin_popcount

int n, a, b;

/*int x(int i)
{
    return (i + i/b) % a;
}
int y(int i)
{
    return i % b;
}*/

new main()
{
    cin >> n >> a >> b;

    int x = a/__gcd(a, b + 1);
    if (x > 1000000000000000000 / b) x = 1000000000000000000;
    else x = x * b;


    set<pii> s;

    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;

        if (b - a + 1 >= x)
        {
            s.ins(mpr(0, x - 1));
        }
        else
        {
            int l = a % x;
            int r = b % x;

            if (l <= r)
            {
                s.ins(mpr(l, r));
            }
            else
            {
                s.ins(mpr(l, x - 1));
                s.ins(mpr(0, r));
            }
        }
    }

    set<pii> nw;

    while (s.size() > 1)
    {
        auto it = s.begin();
        pii a = *it;
        it++;
        pii b = *it;

        if (max(a.fi, b.fi) <= min(a.se, b.se))
        {
            s.erase(s.begin());
            s.erase(s.begin());
            s.ins(mpr(min(a.fi, b.fi), max(a.se, b.se)));
        }
        else
        {
            s.erase(s.begin());
            nw.ins(a);
        }
    }

    nw.ins(*s.begin());

    int res = 0;

    for (pii a : nw)
    {
        res += a.se - a.fi + 1;
    }

    cout << res << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 12 ms 904 KB Output is correct
3 Correct 14 ms 840 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 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 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 12 ms 924 KB Output is correct
17 Correct 120 ms 6444 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 677 ms 284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1295 ms 62868 KB Output is correct
3 Correct 1290 ms 62868 KB Output is correct
4 Correct 1309 ms 62856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1295 ms 62868 KB Output is correct
3 Correct 1290 ms 62868 KB Output is correct
4 Correct 1309 ms 62856 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1292 ms 62992 KB Output is correct
7 Correct 1272 ms 62956 KB Output is correct
8 Correct 1263 ms 63048 KB Output is correct
9 Correct 1327 ms 63052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1295 ms 62868 KB Output is correct
3 Correct 1290 ms 62868 KB Output is correct
4 Correct 1309 ms 62856 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 120 ms 6680 KB Output is correct
7 Correct 118 ms 6608 KB Output is correct
8 Correct 117 ms 6644 KB Output is correct
9 Correct 122 ms 6560 KB Output is correct
10 Correct 147 ms 6740 KB Output is correct
11 Correct 117 ms 6604 KB Output is correct
12 Correct 130 ms 6596 KB Output is correct
13 Correct 140 ms 6612 KB Output is correct
14 Correct 125 ms 6680 KB Output is correct
15 Correct 158 ms 6672 KB Output is correct
16 Correct 125 ms 6672 KB Output is correct
17 Correct 148 ms 6588 KB Output is correct
18 Correct 1321 ms 63172 KB Output is correct
19 Correct 1337 ms 63052 KB Output is correct
20 Correct 1318 ms 63032 KB Output is correct
21 Correct 117 ms 6596 KB Output is correct
22 Correct 122 ms 6560 KB Output is correct
23 Correct 318 ms 412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 126 ms 6560 KB Output is correct
3 Correct 124 ms 6588 KB Output is correct
4 Correct 1349 ms 62984 KB Output is correct
5 Correct 122 ms 6564 KB Output is correct
6 Correct 123 ms 6576 KB Output is correct
7 Correct 124 ms 6624 KB Output is correct
8 Correct 131 ms 6564 KB Output is correct
9 Correct 123 ms 6668 KB Output is correct
10 Correct 133 ms 6648 KB Output is correct
11 Correct 120 ms 6552 KB Output is correct
12 Correct 127 ms 6632 KB Output is correct
13 Correct 124 ms 6600 KB Output is correct
14 Correct 1332 ms 63052 KB Output is correct
15 Correct 122 ms 6620 KB Output is correct
16 Correct 1244 ms 63176 KB Output is correct
17 Correct 1314 ms 62976 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 12 ms 904 KB Output is correct
3 Correct 14 ms 840 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 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 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 12 ms 924 KB Output is correct
17 Correct 120 ms 6444 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 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 0 ms 212 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 677 ms 284 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1295 ms 62868 KB Output is correct
31 Correct 1290 ms 62868 KB Output is correct
32 Correct 1309 ms 62856 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1292 ms 62992 KB Output is correct
35 Correct 1272 ms 62956 KB Output is correct
36 Correct 1263 ms 63048 KB Output is correct
37 Correct 1327 ms 63052 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 120 ms 6680 KB Output is correct
40 Correct 118 ms 6608 KB Output is correct
41 Correct 117 ms 6644 KB Output is correct
42 Correct 122 ms 6560 KB Output is correct
43 Correct 147 ms 6740 KB Output is correct
44 Correct 117 ms 6604 KB Output is correct
45 Correct 130 ms 6596 KB Output is correct
46 Correct 140 ms 6612 KB Output is correct
47 Correct 125 ms 6680 KB Output is correct
48 Correct 158 ms 6672 KB Output is correct
49 Correct 125 ms 6672 KB Output is correct
50 Correct 148 ms 6588 KB Output is correct
51 Correct 1321 ms 63172 KB Output is correct
52 Correct 1337 ms 63052 KB Output is correct
53 Correct 1318 ms 63032 KB Output is correct
54 Correct 117 ms 6596 KB Output is correct
55 Correct 122 ms 6560 KB Output is correct
56 Correct 318 ms 412 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 126 ms 6560 KB Output is correct
59 Correct 124 ms 6588 KB Output is correct
60 Correct 1349 ms 62984 KB Output is correct
61 Correct 122 ms 6564 KB Output is correct
62 Correct 123 ms 6576 KB Output is correct
63 Correct 124 ms 6624 KB Output is correct
64 Correct 131 ms 6564 KB Output is correct
65 Correct 123 ms 6668 KB Output is correct
66 Correct 133 ms 6648 KB Output is correct
67 Correct 120 ms 6552 KB Output is correct
68 Correct 127 ms 6632 KB Output is correct
69 Correct 124 ms 6600 KB Output is correct
70 Correct 1332 ms 63052 KB Output is correct
71 Correct 122 ms 6620 KB Output is correct
72 Correct 1244 ms 63176 KB Output is correct
73 Correct 1314 ms 62976 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 212 KB Output is correct
77 Correct 0 ms 212 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 12 ms 800 KB Output is correct
80 Correct 1381 ms 62896 KB Output is correct
81 Correct 1302 ms 63008 KB Output is correct
82 Correct 1302 ms 63020 KB Output is correct
83 Correct 1310 ms 62896 KB Output is correct
84 Correct 1367 ms 62912 KB Output is correct
85 Correct 1275 ms 62792 KB Output is correct
86 Correct 319 ms 276 KB Output is correct
87 Correct 0 ms 212 KB Output is correct