답안 #712949

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
712949 2023-03-20T14:39:07 Z inventiontime 이상한 기계 (APIO19_strange_device) C++17
100 / 100
684 ms 49784 KB
#include <bits/stdc++.h>
using namespace std;

#define int ll
#define endl '\n' //comment for interactive
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define pb push_back
#define re resize
#define ff first
#define ss second

#define all(x) (x).begin(), (x).end()
#define loop(i, n) for(int i = 0; i < n; i++)
#define loop1(i, n) for(int i = 1; i <= n; i++)
#define print(x) cout << #x << ": " << x << endl << flush

typedef long long ll;
typedef vector<int> vi;
typedef array<int, 2> ii;
typedef array<int, 3> ti;
typedef vector<ii> vii;
typedef vector<ti> vti;
typedef priority_queue<int> pq;

template<class T> bool ckmin(T&a, T b) { bool B = a > b; a = min(a, b); return B; }
template<class T> bool ckmax(T&a, T b) { bool B = a < b; a = max(a, b); return B; }

const int inf = 1e17;
//const int maxn = ;

void solve() {

    int n, a, b;
    cin >> n >> a >> b;

    int p = 1.1e18;
    if((float) b * a / __gcd(a, b+1) < p) 
        p = b * a / __gcd(a, b+1);

    vii intvl;
    loop(i, n) {
        int l, r; cin >> l >> r;
        if(r - l + 1 >= p) intvl.pb({0, p-1});
        else {
            int x = l/p;
            l -= x*p;
            r -= x*p;
            if(r >= p) {
                intvl.pb({l, p-1});
                intvl.pb({0, r-p});
            } else {
                intvl.pb({l, r});
            }
        }
    }

    vii pts;
    for(auto [a, b] : intvl) {
        pts.pb({a, 1});
        pts.pb({b, 2});
    }
    sort(all(pts));

    int st = -1;
    int cnt = 0;
    int res = 0;
    for(auto [x, t] : pts) {
        if(t == 1) {
            if(cnt) cnt++;
            else {
                st = x;
                cnt++;
            }
        } else {
            cnt--;
            if(cnt) {}
            else
                res += x - st + 1;
        }
    }

    cout << res << endl;

}

signed main() {

    fast_io;

    int t = 1; //cin >> t;
    while(t--)
        solve();

    return 0;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 7 ms 1364 KB Output is correct
3 Correct 6 ms 1368 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 324 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 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 7 ms 1364 KB Output is correct
17 Correct 74 ms 6340 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 436 ms 49196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 589 ms 49516 KB Output is correct
3 Correct 571 ms 49440 KB Output is correct
4 Correct 556 ms 49364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 589 ms 49516 KB Output is correct
3 Correct 571 ms 49440 KB Output is correct
4 Correct 556 ms 49364 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 573 ms 49276 KB Output is correct
7 Correct 564 ms 49360 KB Output is correct
8 Correct 558 ms 49308 KB Output is correct
9 Correct 625 ms 49312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 589 ms 49516 KB Output is correct
3 Correct 571 ms 49440 KB Output is correct
4 Correct 556 ms 49364 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 54 ms 6276 KB Output is correct
7 Correct 61 ms 6388 KB Output is correct
8 Correct 53 ms 6472 KB Output is correct
9 Correct 57 ms 6300 KB Output is correct
10 Correct 52 ms 6264 KB Output is correct
11 Correct 58 ms 6384 KB Output is correct
12 Correct 53 ms 6396 KB Output is correct
13 Correct 59 ms 6308 KB Output is correct
14 Correct 53 ms 6308 KB Output is correct
15 Correct 65 ms 6304 KB Output is correct
16 Correct 67 ms 6292 KB Output is correct
17 Correct 55 ms 6296 KB Output is correct
18 Correct 589 ms 49312 KB Output is correct
19 Correct 526 ms 49236 KB Output is correct
20 Correct 657 ms 49428 KB Output is correct
21 Correct 62 ms 6336 KB Output is correct
22 Correct 49 ms 6376 KB Output is correct
23 Correct 160 ms 22564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 64 ms 6272 KB Output is correct
3 Correct 62 ms 6440 KB Output is correct
4 Correct 663 ms 49600 KB Output is correct
5 Correct 64 ms 6304 KB Output is correct
6 Correct 61 ms 6476 KB Output is correct
7 Correct 64 ms 6332 KB Output is correct
8 Correct 63 ms 6320 KB Output is correct
9 Correct 57 ms 6384 KB Output is correct
10 Correct 60 ms 6324 KB Output is correct
11 Correct 61 ms 6304 KB Output is correct
12 Correct 63 ms 6372 KB Output is correct
13 Correct 64 ms 6352 KB Output is correct
14 Correct 619 ms 49412 KB Output is correct
15 Correct 65 ms 6336 KB Output is correct
16 Correct 520 ms 49256 KB Output is correct
17 Correct 556 ms 49460 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 7 ms 1364 KB Output is correct
3 Correct 6 ms 1368 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 324 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 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 7 ms 1364 KB Output is correct
17 Correct 74 ms 6340 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 436 ms 49196 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 589 ms 49516 KB Output is correct
31 Correct 571 ms 49440 KB Output is correct
32 Correct 556 ms 49364 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 573 ms 49276 KB Output is correct
35 Correct 564 ms 49360 KB Output is correct
36 Correct 558 ms 49308 KB Output is correct
37 Correct 625 ms 49312 KB Output is correct
38 Correct 1 ms 320 KB Output is correct
39 Correct 54 ms 6276 KB Output is correct
40 Correct 61 ms 6388 KB Output is correct
41 Correct 53 ms 6472 KB Output is correct
42 Correct 57 ms 6300 KB Output is correct
43 Correct 52 ms 6264 KB Output is correct
44 Correct 58 ms 6384 KB Output is correct
45 Correct 53 ms 6396 KB Output is correct
46 Correct 59 ms 6308 KB Output is correct
47 Correct 53 ms 6308 KB Output is correct
48 Correct 65 ms 6304 KB Output is correct
49 Correct 67 ms 6292 KB Output is correct
50 Correct 55 ms 6296 KB Output is correct
51 Correct 589 ms 49312 KB Output is correct
52 Correct 526 ms 49236 KB Output is correct
53 Correct 657 ms 49428 KB Output is correct
54 Correct 62 ms 6336 KB Output is correct
55 Correct 49 ms 6376 KB Output is correct
56 Correct 160 ms 22564 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 64 ms 6272 KB Output is correct
59 Correct 62 ms 6440 KB Output is correct
60 Correct 663 ms 49600 KB Output is correct
61 Correct 64 ms 6304 KB Output is correct
62 Correct 61 ms 6476 KB Output is correct
63 Correct 64 ms 6332 KB Output is correct
64 Correct 63 ms 6320 KB Output is correct
65 Correct 57 ms 6384 KB Output is correct
66 Correct 60 ms 6324 KB Output is correct
67 Correct 61 ms 6304 KB Output is correct
68 Correct 63 ms 6372 KB Output is correct
69 Correct 64 ms 6352 KB Output is correct
70 Correct 619 ms 49412 KB Output is correct
71 Correct 65 ms 6336 KB Output is correct
72 Correct 520 ms 49256 KB Output is correct
73 Correct 556 ms 49460 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 1 ms 316 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 1 ms 316 KB Output is correct
79 Correct 6 ms 1480 KB Output is correct
80 Correct 667 ms 49784 KB Output is correct
81 Correct 669 ms 49704 KB Output is correct
82 Correct 663 ms 49692 KB Output is correct
83 Correct 684 ms 49680 KB Output is correct
84 Correct 672 ms 49612 KB Output is correct
85 Correct 634 ms 49564 KB Output is correct
86 Correct 219 ms 33164 KB Output is correct
87 Correct 1 ms 212 KB Output is correct