답안 #795553

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
795553 2023-07-27T11:14:36 Z RecursiveCo 이상한 기계 (APIO19_strange_device) C++14
100 / 100
564 ms 69032 KB
// CF template, version 3.0

#include <bits/stdc++.h>

using namespace std;

#define improvePerformance ios_base::sync_with_stdio(false); cin.tie(0)
#define getTest int t; cin >> t
#define eachTest for (int _var=0;_var<t;_var++)
#define get(name) int (name); cin >> (name)
#define out(o) cout << (o)
#define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
#define sortl(name) sort((name).begin(), (name).end())
#define rev(name) reverse((name).begin(), (name).end())
#define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
#define decision(b) if (b){out("YES");}else{out("NO");}

#define int long long int

int gcd(int a, int b) {
    int A = min(a, b);
    int B = max(a, b);
    if (A == 0) return B;
    return gcd(A, B % A);
}

signed main() {
    improvePerformance;
    //getTest;

    //eachTest {
        get(n);
        get(A);
        get(B);
        bool toobig = (1e18 + A - 1) / A <= B; // should be good enough, theoretically.
        vector<pair<int, int>> events;
        int large;
        if (!toobig) large = A * B / gcd(A, B + 1);
        forto(n, i) {
            get(l);
            get(r);
            if (!toobig) {
                if (r - l + 1 >= A * B) {
                    out(large);
                    return 0;
                }
                l %= large;
                r %= large;
            }
            events.push_back({l, -1});
            events.push_back({r, 1});
            if (r < l) {
                events.push_back({0, -1});
                events.push_back({large - 1, 1});
            }
        }
        int ans = 0;
        int last = -1;
        int m = events.size();
        sortl(events);
        int balance = 0;
        forto(m, i) {
            balance -= events[i].second;
            if (last == -1 && balance > 0) {
                last = events[i].first;
            } else if (balance == 0) {
                ans += (events[i].first - last + 1);
                last = -1;
            }
        }
        out(ans);
    //}
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:10:23: warning: unnecessary parentheses in declaration of 'n' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
strange_device.cpp:32:9: note: in expansion of macro 'get'
   32 |         get(n);
      |         ^~~
strange_device.cpp:10:23: warning: unnecessary parentheses in declaration of 'A' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
strange_device.cpp:33:9: note: in expansion of macro 'get'
   33 |         get(A);
      |         ^~~
strange_device.cpp:10:23: warning: unnecessary parentheses in declaration of 'B' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
strange_device.cpp:34:9: note: in expansion of macro 'get'
   34 |         get(B);
      |         ^~~
strange_device.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
strange_device.cpp:39:9: note: in expansion of macro 'forto'
   39 |         forto(n, i) {
      |         ^~~~~
strange_device.cpp:10:23: warning: unnecessary parentheses in declaration of 'l' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
strange_device.cpp:40:13: note: in expansion of macro 'get'
   40 |             get(l);
      |             ^~~
strange_device.cpp:10:23: warning: unnecessary parentheses in declaration of 'r' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
strange_device.cpp:41:13: note: in expansion of macro 'get'
   41 |             get(r);
      |             ^~~
strange_device.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
strange_device.cpp:62:9: note: in expansion of macro 'forto'
   62 |         forto(m, i) {
      |         ^~~~~
strange_device.cpp:54:41: warning: 'large' may be used uninitialized in this function [-Wmaybe-uninitialized]
   54 |                 events.push_back({large - 1, 1});
      |                                   ~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 856 KB Output is correct
3 Correct 4 ms 984 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 0 ms 320 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 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 244 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 6 ms 1364 KB Output is correct
17 Correct 48 ms 7316 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 290 ms 33188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 387 ms 33280 KB Output is correct
3 Correct 426 ms 33284 KB Output is correct
4 Correct 405 ms 68948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 387 ms 33280 KB Output is correct
3 Correct 426 ms 33284 KB Output is correct
4 Correct 405 ms 68948 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 417 ms 68896 KB Output is correct
7 Correct 412 ms 68920 KB Output is correct
8 Correct 403 ms 68836 KB Output is correct
9 Correct 466 ms 69032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 387 ms 33280 KB Output is correct
3 Correct 426 ms 33284 KB Output is correct
4 Correct 405 ms 68948 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 37 ms 7268 KB Output is correct
7 Correct 39 ms 7204 KB Output is correct
8 Correct 38 ms 7232 KB Output is correct
9 Correct 49 ms 7404 KB Output is correct
10 Correct 36 ms 7236 KB Output is correct
11 Correct 38 ms 7296 KB Output is correct
12 Correct 36 ms 7232 KB Output is correct
13 Correct 51 ms 7304 KB Output is correct
14 Correct 36 ms 7252 KB Output is correct
15 Correct 47 ms 7268 KB Output is correct
16 Correct 51 ms 7292 KB Output is correct
17 Correct 39 ms 7340 KB Output is correct
18 Correct 450 ms 68932 KB Output is correct
19 Correct 401 ms 68968 KB Output is correct
20 Correct 489 ms 68884 KB Output is correct
21 Correct 44 ms 7276 KB Output is correct
22 Correct 33 ms 7256 KB Output is correct
23 Correct 110 ms 26704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 42 ms 4892 KB Output is correct
3 Correct 46 ms 5024 KB Output is correct
4 Correct 533 ms 33336 KB Output is correct
5 Correct 41 ms 4888 KB Output is correct
6 Correct 41 ms 4904 KB Output is correct
7 Correct 50 ms 4912 KB Output is correct
8 Correct 44 ms 4860 KB Output is correct
9 Correct 42 ms 4936 KB Output is correct
10 Correct 44 ms 4968 KB Output is correct
11 Correct 41 ms 4940 KB Output is correct
12 Correct 36 ms 4840 KB Output is correct
13 Correct 54 ms 4932 KB Output is correct
14 Correct 450 ms 33248 KB Output is correct
15 Correct 46 ms 5280 KB Output is correct
16 Correct 395 ms 68880 KB Output is correct
17 Correct 454 ms 68844 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 856 KB Output is correct
3 Correct 4 ms 984 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 0 ms 320 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 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 244 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 6 ms 1364 KB Output is correct
17 Correct 48 ms 7316 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 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 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 290 ms 33188 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 387 ms 33280 KB Output is correct
31 Correct 426 ms 33284 KB Output is correct
32 Correct 405 ms 68948 KB Output is correct
33 Correct 1 ms 324 KB Output is correct
34 Correct 417 ms 68896 KB Output is correct
35 Correct 412 ms 68920 KB Output is correct
36 Correct 403 ms 68836 KB Output is correct
37 Correct 466 ms 69032 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 37 ms 7268 KB Output is correct
40 Correct 39 ms 7204 KB Output is correct
41 Correct 38 ms 7232 KB Output is correct
42 Correct 49 ms 7404 KB Output is correct
43 Correct 36 ms 7236 KB Output is correct
44 Correct 38 ms 7296 KB Output is correct
45 Correct 36 ms 7232 KB Output is correct
46 Correct 51 ms 7304 KB Output is correct
47 Correct 36 ms 7252 KB Output is correct
48 Correct 47 ms 7268 KB Output is correct
49 Correct 51 ms 7292 KB Output is correct
50 Correct 39 ms 7340 KB Output is correct
51 Correct 450 ms 68932 KB Output is correct
52 Correct 401 ms 68968 KB Output is correct
53 Correct 489 ms 68884 KB Output is correct
54 Correct 44 ms 7276 KB Output is correct
55 Correct 33 ms 7256 KB Output is correct
56 Correct 110 ms 26704 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 42 ms 4892 KB Output is correct
59 Correct 46 ms 5024 KB Output is correct
60 Correct 533 ms 33336 KB Output is correct
61 Correct 41 ms 4888 KB Output is correct
62 Correct 41 ms 4904 KB Output is correct
63 Correct 50 ms 4912 KB Output is correct
64 Correct 44 ms 4860 KB Output is correct
65 Correct 42 ms 4936 KB Output is correct
66 Correct 44 ms 4968 KB Output is correct
67 Correct 41 ms 4940 KB Output is correct
68 Correct 36 ms 4840 KB Output is correct
69 Correct 54 ms 4932 KB Output is correct
70 Correct 450 ms 33248 KB Output is correct
71 Correct 46 ms 5280 KB Output is correct
72 Correct 395 ms 68880 KB Output is correct
73 Correct 454 ms 68844 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 1 ms 212 KB Output is correct
79 Correct 4 ms 1240 KB Output is correct
80 Correct 553 ms 68888 KB Output is correct
81 Correct 564 ms 68908 KB Output is correct
82 Correct 506 ms 68908 KB Output is correct
83 Correct 491 ms 68824 KB Output is correct
84 Correct 497 ms 68700 KB Output is correct
85 Correct 485 ms 68628 KB Output is correct
86 Correct 114 ms 26656 KB Output is correct
87 Correct 1 ms 212 KB Output is correct