답안 #926594

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
926594 2024-02-13T11:53:18 Z TAhmed33 이상한 기계 (APIO19_strange_device) C++
100 / 100
1175 ms 118676 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 ll2;
int main () {
    ll n, a, b; cin >> n >> a >> b;
    ll2 u = a; u *= b; u /= __gcd(a, b + 1);
    vector <pair <ll, ll>> arr(n); 
    bool flag = 0;
    for (auto &[x, y] : arr) {
        cin >> x >> y;
        flag |= y - x + 1 >= u;
    }
    if (flag) {
        cout << (ll)u << '\n';
        return 0;
    }
    vector <pair <ll2, ll2>> intervals;
    for (auto [x, y] : arr) {
        ll2 g = x % u, h = y % u;
        if (g <= h) {
            intervals.push_back({g, h});
        } else {
            intervals.push_back({g, u - 1});
            intervals.push_back({0, h});
        }
    }
    sort(intervals.begin(), intervals.end(), [] (pair <ll2, ll2> &x, pair <ll2, ll2> &y) {
        return x.first == y.first ? x.second > y.second : x.first < y.first;
    });
    stack <pair <ll2, ll2>> dd;
    for (auto &[x, y] : intervals) {
        while (!dd.empty() && !(dd.top().first > y || dd.top().second < x)) {
            x = min(x, dd.top().first); y = max(y, dd.top().second);
            dd.pop(); 
        }
        dd.push({x, y});
    }
    ll2 sum = 0;
    while (!dd.empty()) {
        auto k = dd.top(); dd.pop();
        sum += k.second - k.first + 1;
    }
    cout << ll(sum) << '\n';
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:10:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   10 |     for (auto &[x, y] : arr) {
      |                ^
strange_device.cpp:19:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   19 |     for (auto [x, y] : arr) {
      |               ^
strange_device.cpp:32:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   32 |     for (auto &[x, y] : intervals) {
      |                ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 10 ms 1240 KB Output is correct
3 Correct 11 ms 1496 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 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 0 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 1496 KB Output is correct
17 Correct 112 ms 10688 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 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 915 ms 62772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1034 ms 80040 KB Output is correct
3 Correct 1067 ms 117844 KB Output is correct
4 Correct 1037 ms 117284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1034 ms 80040 KB Output is correct
3 Correct 1067 ms 117844 KB Output is correct
4 Correct 1037 ms 117284 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1069 ms 117464 KB Output is correct
7 Correct 1070 ms 117668 KB Output is correct
8 Correct 1045 ms 118676 KB Output is correct
9 Correct 1102 ms 118596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1034 ms 80040 KB Output is correct
3 Correct 1067 ms 117844 KB Output is correct
4 Correct 1037 ms 117284 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 103 ms 12736 KB Output is correct
7 Correct 106 ms 12736 KB Output is correct
8 Correct 102 ms 12992 KB Output is correct
9 Correct 106 ms 12220 KB Output is correct
10 Correct 105 ms 11964 KB Output is correct
11 Correct 103 ms 11964 KB Output is correct
12 Correct 102 ms 12220 KB Output is correct
13 Correct 108 ms 12476 KB Output is correct
14 Correct 117 ms 11952 KB Output is correct
15 Correct 108 ms 13228 KB Output is correct
16 Correct 114 ms 12480 KB Output is correct
17 Correct 109 ms 11936 KB Output is correct
18 Correct 1050 ms 118304 KB Output is correct
19 Correct 1043 ms 117156 KB Output is correct
20 Correct 1133 ms 117668 KB Output is correct
21 Correct 113 ms 11964 KB Output is correct
22 Correct 100 ms 12992 KB Output is correct
23 Correct 330 ms 35940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 110 ms 8256 KB Output is correct
3 Correct 107 ms 12992 KB Output is correct
4 Correct 1172 ms 118092 KB Output is correct
5 Correct 110 ms 11932 KB Output is correct
6 Correct 106 ms 11964 KB Output is correct
7 Correct 106 ms 11952 KB Output is correct
8 Correct 107 ms 11936 KB Output is correct
9 Correct 106 ms 12044 KB Output is correct
10 Correct 113 ms 12040 KB Output is correct
11 Correct 107 ms 12064 KB Output is correct
12 Correct 102 ms 12572 KB Output is correct
13 Correct 107 ms 12732 KB Output is correct
14 Correct 1111 ms 117272 KB Output is correct
15 Correct 106 ms 11700 KB Output is correct
16 Correct 1039 ms 118152 KB Output is correct
17 Correct 1038 ms 117212 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 10 ms 1240 KB Output is correct
3 Correct 11 ms 1496 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 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 0 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 1496 KB Output is correct
17 Correct 112 ms 10688 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 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 915 ms 62772 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1034 ms 80040 KB Output is correct
31 Correct 1067 ms 117844 KB Output is correct
32 Correct 1037 ms 117284 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1069 ms 117464 KB Output is correct
35 Correct 1070 ms 117668 KB Output is correct
36 Correct 1045 ms 118676 KB Output is correct
37 Correct 1102 ms 118596 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 103 ms 12736 KB Output is correct
40 Correct 106 ms 12736 KB Output is correct
41 Correct 102 ms 12992 KB Output is correct
42 Correct 106 ms 12220 KB Output is correct
43 Correct 105 ms 11964 KB Output is correct
44 Correct 103 ms 11964 KB Output is correct
45 Correct 102 ms 12220 KB Output is correct
46 Correct 108 ms 12476 KB Output is correct
47 Correct 117 ms 11952 KB Output is correct
48 Correct 108 ms 13228 KB Output is correct
49 Correct 114 ms 12480 KB Output is correct
50 Correct 109 ms 11936 KB Output is correct
51 Correct 1050 ms 118304 KB Output is correct
52 Correct 1043 ms 117156 KB Output is correct
53 Correct 1133 ms 117668 KB Output is correct
54 Correct 113 ms 11964 KB Output is correct
55 Correct 100 ms 12992 KB Output is correct
56 Correct 330 ms 35940 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 110 ms 8256 KB Output is correct
59 Correct 107 ms 12992 KB Output is correct
60 Correct 1172 ms 118092 KB Output is correct
61 Correct 110 ms 11932 KB Output is correct
62 Correct 106 ms 11964 KB Output is correct
63 Correct 106 ms 11952 KB Output is correct
64 Correct 107 ms 11936 KB Output is correct
65 Correct 106 ms 12044 KB Output is correct
66 Correct 113 ms 12040 KB Output is correct
67 Correct 107 ms 12064 KB Output is correct
68 Correct 102 ms 12572 KB Output is correct
69 Correct 107 ms 12732 KB Output is correct
70 Correct 1111 ms 117272 KB Output is correct
71 Correct 106 ms 11700 KB Output is correct
72 Correct 1039 ms 118152 KB Output is correct
73 Correct 1038 ms 117212 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 1496 KB Output is correct
80 Correct 1175 ms 117148 KB Output is correct
81 Correct 1173 ms 117648 KB Output is correct
82 Correct 1104 ms 118000 KB Output is correct
83 Correct 1119 ms 118080 KB Output is correct
84 Correct 1112 ms 117140 KB Output is correct
85 Correct 1096 ms 118500 KB Output is correct
86 Correct 329 ms 35768 KB Output is correct
87 Correct 0 ms 344 KB Output is correct