답안 #211474

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
211474 2020-03-20T13:06:23 Z VEGAnn 이상한 기계 (APIO19_strange_device) C++14
100 / 100
2998 ms 33564 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define ft first
#define sd second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define pll pair<ll, ll>
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long ll;
//typedef long long __int128;
vector<pll> seg;
int n;
ll A, B;

int main(){

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#else
    ios_base::sync_with_stdio(0); cin.tie(0);
#endif // _LOCAL

    cin >> n >> A >> B;

//    ll fi = 1;
//
//    while ((fi + fi / B) % A != 0 || fi % B != 0)
//        fi++;
//
//    cout << fi << '\n';

    ll fi = A;

    if (A >= B) {

        while (fi <= ll(1e18) && fi % (B + 1) > 0)
            fi += A;

        if (fi <= ll(1e18))
            fi -= fi / (B + 1);

    } else {
        fi = B;

        while (fi <= ll(1e18) && ((fi + fi / B) % A != 0))
            fi += B;
    }

//    cout << fi << '\n';

    seg.clear();

    for (int i = 0; i < n; i++){
        ll l, r; cin >> l >> r;

        if (r - l + 1 >= fi){
            seg.PB(MP(0, fi - 1));
            continue;
        }

        ll vl = ((l - 1) / fi) * fi + fi;

        if (vl > r){
            vl -= fi;
            seg.PB(MP(l - vl, r - vl));
        } else {
            vl -= fi;
            seg.PB(MP(l - vl, fi - 1));
            vl += fi;
            seg.PB(MP(0ll, r - vl));
        }
    }

    sort(all(seg));

    ll lst = -1, ans = 0;

    for (pll cr : seg)
        if (cr.ft > lst){
            ans += cr.sd - cr.ft + 1ll;
            lst = cr.sd;
        } else {

            ans += max(lst, cr.sd) - lst;
            lst = max(lst, cr.sd);
        }

    cout << ans << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 10 ms 1152 KB Output is correct
3 Correct 10 ms 1152 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 9 ms 1152 KB Output is correct
17 Correct 61 ms 5240 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 459 ms 33564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 520 ms 17532 KB Output is correct
3 Correct 508 ms 17520 KB Output is correct
4 Correct 490 ms 17368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 520 ms 17532 KB Output is correct
3 Correct 508 ms 17520 KB Output is correct
4 Correct 490 ms 17368 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 485 ms 17360 KB Output is correct
7 Correct 499 ms 17456 KB Output is correct
8 Correct 480 ms 17360 KB Output is correct
9 Correct 526 ms 17104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 520 ms 17532 KB Output is correct
3 Correct 508 ms 17520 KB Output is correct
4 Correct 490 ms 17368 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 55 ms 5484 KB Output is correct
7 Correct 60 ms 5488 KB Output is correct
8 Correct 53 ms 5444 KB Output is correct
9 Correct 56 ms 5484 KB Output is correct
10 Correct 52 ms 5484 KB Output is correct
11 Correct 58 ms 5480 KB Output is correct
12 Correct 58 ms 5480 KB Output is correct
13 Correct 57 ms 5484 KB Output is correct
14 Correct 55 ms 5484 KB Output is correct
15 Correct 61 ms 5484 KB Output is correct
16 Correct 62 ms 5484 KB Output is correct
17 Correct 69 ms 5484 KB Output is correct
18 Correct 492 ms 17364 KB Output is correct
19 Correct 497 ms 17368 KB Output is correct
20 Correct 558 ms 17368 KB Output is correct
21 Correct 66 ms 5480 KB Output is correct
22 Correct 52 ms 5480 KB Output is correct
23 Correct 178 ms 22228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 57 ms 5352 KB Output is correct
3 Correct 62 ms 5100 KB Output is correct
4 Correct 577 ms 17280 KB Output is correct
5 Correct 81 ms 5352 KB Output is correct
6 Correct 81 ms 5356 KB Output is correct
7 Correct 83 ms 5376 KB Output is correct
8 Correct 59 ms 5356 KB Output is correct
9 Correct 81 ms 5360 KB Output is correct
10 Correct 56 ms 5352 KB Output is correct
11 Correct 60 ms 5356 KB Output is correct
12 Correct 54 ms 5356 KB Output is correct
13 Correct 59 ms 5356 KB Output is correct
14 Correct 551 ms 17108 KB Output is correct
15 Correct 56 ms 5352 KB Output is correct
16 Correct 502 ms 17112 KB Output is correct
17 Correct 495 ms 17056 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 10 ms 1152 KB Output is correct
3 Correct 10 ms 1152 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 9 ms 1152 KB Output is correct
17 Correct 61 ms 5240 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 459 ms 33564 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 520 ms 17532 KB Output is correct
31 Correct 508 ms 17520 KB Output is correct
32 Correct 490 ms 17368 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 485 ms 17360 KB Output is correct
35 Correct 499 ms 17456 KB Output is correct
36 Correct 480 ms 17360 KB Output is correct
37 Correct 526 ms 17104 KB Output is correct
38 Correct 4 ms 384 KB Output is correct
39 Correct 55 ms 5484 KB Output is correct
40 Correct 60 ms 5488 KB Output is correct
41 Correct 53 ms 5444 KB Output is correct
42 Correct 56 ms 5484 KB Output is correct
43 Correct 52 ms 5484 KB Output is correct
44 Correct 58 ms 5480 KB Output is correct
45 Correct 58 ms 5480 KB Output is correct
46 Correct 57 ms 5484 KB Output is correct
47 Correct 55 ms 5484 KB Output is correct
48 Correct 61 ms 5484 KB Output is correct
49 Correct 62 ms 5484 KB Output is correct
50 Correct 69 ms 5484 KB Output is correct
51 Correct 492 ms 17364 KB Output is correct
52 Correct 497 ms 17368 KB Output is correct
53 Correct 558 ms 17368 KB Output is correct
54 Correct 66 ms 5480 KB Output is correct
55 Correct 52 ms 5480 KB Output is correct
56 Correct 178 ms 22228 KB Output is correct
57 Correct 4 ms 384 KB Output is correct
58 Correct 57 ms 5352 KB Output is correct
59 Correct 62 ms 5100 KB Output is correct
60 Correct 577 ms 17280 KB Output is correct
61 Correct 81 ms 5352 KB Output is correct
62 Correct 81 ms 5356 KB Output is correct
63 Correct 83 ms 5376 KB Output is correct
64 Correct 59 ms 5356 KB Output is correct
65 Correct 81 ms 5360 KB Output is correct
66 Correct 56 ms 5352 KB Output is correct
67 Correct 60 ms 5356 KB Output is correct
68 Correct 54 ms 5356 KB Output is correct
69 Correct 59 ms 5356 KB Output is correct
70 Correct 551 ms 17108 KB Output is correct
71 Correct 56 ms 5352 KB Output is correct
72 Correct 502 ms 17112 KB Output is correct
73 Correct 495 ms 17056 KB Output is correct
74 Correct 5 ms 384 KB Output is correct
75 Correct 4 ms 384 KB Output is correct
76 Correct 4 ms 384 KB Output is correct
77 Correct 7 ms 384 KB Output is correct
78 Correct 4 ms 288 KB Output is correct
79 Correct 10 ms 1144 KB Output is correct
80 Correct 564 ms 17112 KB Output is correct
81 Correct 590 ms 17356 KB Output is correct
82 Correct 553 ms 17108 KB Output is correct
83 Correct 1832 ms 17108 KB Output is correct
84 Correct 2998 ms 17108 KB Output is correct
85 Correct 560 ms 16980 KB Output is correct
86 Correct 187 ms 18156 KB Output is correct
87 Correct 18 ms 384 KB Output is correct