답안 #977108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
977108 2024-05-07T11:47:28 Z akacool445k 이상한 기계 (APIO19_strange_device) C++14
100 / 100
1214 ms 63484 KB
#include <bits/stdc++.h>
 
using namespace std;
#define ff first
#define ss second
#define int long long
const long long mod = 1e9 + 7;
const long long shrek = (1 << 30);
int gcd(int a, int b) {
	if(a == 0) return b;
	if(b == 0) return a;
	return gcd(b % a, a);
}
signed main() {
    int A, B, n;
    cin >> n >> A >> B;
    int k =  gcd(A, B + 1);
    double fuk = 1.0 * A * B / k;
    int gay = 1e18;
    if(fuk <= 1e18) gay = B * A / k;
    set<pair<int, int>> v;
    bool cmd = 0;
    for(int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        if(y - x + 1 >= gay) {
            cmd = 1;
            continue;
        } else {
            x = x % gay;
            y = y % gay;
            if(x <= y) {
                v.insert({x, y});
            } else {
                v.insert({0, y});
                v.insert({x, gay - 1});
            }
        }
    }
    v.insert({2e18, 2e18});
    if(cmd == 1) {
        cout << gay << '\n';
        return 0;
    }
    int ans = 0;
    int l, r;
    l = (*v.begin()).ff; 
    r = l;
    for(auto x : v) {
        if(r < x.ff) {
            ans = ans + r - l + 1;
            l = x.ff;
            r = x.ss;
        }
        r = max(r, x.ss);
    }
    cout << ans << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 13 ms 892 KB Output is correct
3 Correct 12 ms 868 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 10 ms 860 KB Output is correct
17 Correct 107 ms 6432 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 650 ms 412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 548 KB Output is correct
2 Correct 1104 ms 62864 KB Output is correct
3 Correct 1129 ms 63228 KB Output is correct
4 Correct 1151 ms 63036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 548 KB Output is correct
2 Correct 1104 ms 62864 KB Output is correct
3 Correct 1129 ms 63228 KB Output is correct
4 Correct 1151 ms 63036 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1124 ms 63012 KB Output is correct
7 Correct 1129 ms 63000 KB Output is correct
8 Correct 1108 ms 62852 KB Output is correct
9 Correct 1119 ms 62868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 548 KB Output is correct
2 Correct 1104 ms 62864 KB Output is correct
3 Correct 1129 ms 63228 KB Output is correct
4 Correct 1151 ms 63036 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 112 ms 6460 KB Output is correct
7 Correct 117 ms 6440 KB Output is correct
8 Correct 104 ms 6484 KB Output is correct
9 Correct 108 ms 6508 KB Output is correct
10 Correct 108 ms 6716 KB Output is correct
11 Correct 111 ms 6556 KB Output is correct
12 Correct 103 ms 6640 KB Output is correct
13 Correct 107 ms 6484 KB Output is correct
14 Correct 115 ms 6704 KB Output is correct
15 Correct 111 ms 6560 KB Output is correct
16 Correct 108 ms 6496 KB Output is correct
17 Correct 106 ms 6480 KB Output is correct
18 Correct 1091 ms 62900 KB Output is correct
19 Correct 1160 ms 63200 KB Output is correct
20 Correct 1147 ms 62920 KB Output is correct
21 Correct 108 ms 6480 KB Output is correct
22 Correct 111 ms 6544 KB Output is correct
23 Correct 324 ms 404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 115 ms 6608 KB Output is correct
3 Correct 131 ms 6480 KB Output is correct
4 Correct 1137 ms 63192 KB Output is correct
5 Correct 117 ms 6484 KB Output is correct
6 Correct 108 ms 6484 KB Output is correct
7 Correct 131 ms 6720 KB Output is correct
8 Correct 114 ms 6660 KB Output is correct
9 Correct 109 ms 6480 KB Output is correct
10 Correct 119 ms 6480 KB Output is correct
11 Correct 107 ms 6480 KB Output is correct
12 Correct 107 ms 6636 KB Output is correct
13 Correct 113 ms 6580 KB Output is correct
14 Correct 1214 ms 62960 KB Output is correct
15 Correct 108 ms 6484 KB Output is correct
16 Correct 1123 ms 63100 KB Output is correct
17 Correct 1085 ms 63024 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 13 ms 892 KB Output is correct
3 Correct 12 ms 868 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 10 ms 860 KB Output is correct
17 Correct 107 ms 6432 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 2 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 650 ms 412 KB Output is correct
29 Correct 0 ms 548 KB Output is correct
30 Correct 1104 ms 62864 KB Output is correct
31 Correct 1129 ms 63228 KB Output is correct
32 Correct 1151 ms 63036 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1124 ms 63012 KB Output is correct
35 Correct 1129 ms 63000 KB Output is correct
36 Correct 1108 ms 62852 KB Output is correct
37 Correct 1119 ms 62868 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 112 ms 6460 KB Output is correct
40 Correct 117 ms 6440 KB Output is correct
41 Correct 104 ms 6484 KB Output is correct
42 Correct 108 ms 6508 KB Output is correct
43 Correct 108 ms 6716 KB Output is correct
44 Correct 111 ms 6556 KB Output is correct
45 Correct 103 ms 6640 KB Output is correct
46 Correct 107 ms 6484 KB Output is correct
47 Correct 115 ms 6704 KB Output is correct
48 Correct 111 ms 6560 KB Output is correct
49 Correct 108 ms 6496 KB Output is correct
50 Correct 106 ms 6480 KB Output is correct
51 Correct 1091 ms 62900 KB Output is correct
52 Correct 1160 ms 63200 KB Output is correct
53 Correct 1147 ms 62920 KB Output is correct
54 Correct 108 ms 6480 KB Output is correct
55 Correct 111 ms 6544 KB Output is correct
56 Correct 324 ms 404 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 115 ms 6608 KB Output is correct
59 Correct 131 ms 6480 KB Output is correct
60 Correct 1137 ms 63192 KB Output is correct
61 Correct 117 ms 6484 KB Output is correct
62 Correct 108 ms 6484 KB Output is correct
63 Correct 131 ms 6720 KB Output is correct
64 Correct 114 ms 6660 KB Output is correct
65 Correct 109 ms 6480 KB Output is correct
66 Correct 119 ms 6480 KB Output is correct
67 Correct 107 ms 6480 KB Output is correct
68 Correct 107 ms 6636 KB Output is correct
69 Correct 113 ms 6580 KB Output is correct
70 Correct 1214 ms 62960 KB Output is correct
71 Correct 108 ms 6484 KB Output is correct
72 Correct 1123 ms 63100 KB Output is correct
73 Correct 1085 ms 63024 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 11 ms 972 KB Output is correct
80 Correct 1123 ms 62836 KB Output is correct
81 Correct 1163 ms 62816 KB Output is correct
82 Correct 1127 ms 63244 KB Output is correct
83 Correct 1178 ms 63484 KB Output is correct
84 Correct 1170 ms 62864 KB Output is correct
85 Correct 1124 ms 62900 KB Output is correct
86 Correct 304 ms 592 KB Output is correct
87 Correct 0 ms 348 KB Output is correct