답안 #240099

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
240099 2020-06-18T02:33:02 Z wiwiho 이상한 기계 (APIO19_strange_device) C++14
100 / 100
904 ms 45892 KB
//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) ((a + b - 1) / b)
#define tomax(a, b) (a = max(a, b))
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

//#define TEST

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

int main(){
    StarBurstStream

    int n;
    cin >> n;

    ll a, b;
    cin >> a >> b;

    ll x = a / __gcd(a, b + 1);
    ll t = x > iceil((1LL << 60), b) ? (1LL << 60) : x * b;

    vector<pll> e;
    for(int i = 0; i < n; i++){

        ll l, r;
        cin >> l >> r;

        if(r - l + 1 >= t){
            cout << t << "\n";
            return 0;
        }

        if(l % t <= r % t){
            e.eb(mp(l % t, 1));
            e.eb(mp(r % t + 1, 0));
        }
        else{
            e.eb(mp(l % t, 1));
            e.eb(mp(t, 0));
            e.eb(mp(0, 1));
            e.eb(mp(r % t + 1, 0));
        }
    }

//    cerr << t << "\n";

    ll ans = 0, lst = -1;
    int cnt = 0;
    lsort(e);

    for(pll i : e){
//        cerr << i.F << " " << i.S << " " << lst << "\n";
        if(i.S){
            cnt++;
            if(lst == -1) lst = i.F;
        }
        else{
            cnt--;
            if(cnt == 0){
//                cerr << "test " << lst << " " << i.F << "\n";
                ans += i.F - lst;
                lst = -1;
            }
        }
//        cerr << cnt << " " << ans << "\n";
    }

    cout << ans << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 11 ms 1024 KB Output is correct
3 Correct 10 ms 1024 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 11 ms 1024 KB Output is correct
17 Correct 75 ms 4588 KB Output is correct
18 Correct 4 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 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 420 ms 33492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 637 ms 33244 KB Output is correct
3 Correct 726 ms 33344 KB Output is correct
4 Correct 617 ms 33348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 637 ms 33244 KB Output is correct
3 Correct 726 ms 33344 KB Output is correct
4 Correct 617 ms 33348 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 731 ms 33344 KB Output is correct
7 Correct 650 ms 33340 KB Output is correct
8 Correct 648 ms 33344 KB Output is correct
9 Correct 739 ms 33344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 637 ms 33244 KB Output is correct
3 Correct 726 ms 33344 KB Output is correct
4 Correct 617 ms 33348 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 69 ms 4588 KB Output is correct
7 Correct 75 ms 4588 KB Output is correct
8 Correct 65 ms 4588 KB Output is correct
9 Correct 69 ms 4596 KB Output is correct
10 Correct 62 ms 4588 KB Output is correct
11 Correct 77 ms 4588 KB Output is correct
12 Correct 72 ms 4588 KB Output is correct
13 Correct 74 ms 4596 KB Output is correct
14 Correct 66 ms 4592 KB Output is correct
15 Correct 79 ms 4596 KB Output is correct
16 Correct 74 ms 4588 KB Output is correct
17 Correct 76 ms 4564 KB Output is correct
18 Correct 641 ms 33348 KB Output is correct
19 Correct 640 ms 33620 KB Output is correct
20 Correct 791 ms 33472 KB Output is correct
21 Correct 76 ms 4588 KB Output is correct
22 Correct 58 ms 4584 KB Output is correct
23 Correct 192 ms 16980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 72 ms 4580 KB Output is correct
3 Correct 76 ms 4588 KB Output is correct
4 Correct 871 ms 33344 KB Output is correct
5 Correct 73 ms 4588 KB Output is correct
6 Correct 78 ms 4596 KB Output is correct
7 Correct 86 ms 4596 KB Output is correct
8 Correct 74 ms 4716 KB Output is correct
9 Correct 69 ms 4588 KB Output is correct
10 Correct 72 ms 4584 KB Output is correct
11 Correct 70 ms 4596 KB Output is correct
12 Correct 68 ms 4584 KB Output is correct
13 Correct 78 ms 4588 KB Output is correct
14 Correct 738 ms 33344 KB Output is correct
15 Correct 75 ms 4588 KB Output is correct
16 Correct 600 ms 33344 KB Output is correct
17 Correct 637 ms 33344 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 11 ms 1024 KB Output is correct
3 Correct 10 ms 1024 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 11 ms 1024 KB Output is correct
17 Correct 75 ms 4588 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 6 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 420 ms 33492 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 637 ms 33244 KB Output is correct
31 Correct 726 ms 33344 KB Output is correct
32 Correct 617 ms 33348 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 731 ms 33344 KB Output is correct
35 Correct 650 ms 33340 KB Output is correct
36 Correct 648 ms 33344 KB Output is correct
37 Correct 739 ms 33344 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 69 ms 4588 KB Output is correct
40 Correct 75 ms 4588 KB Output is correct
41 Correct 65 ms 4588 KB Output is correct
42 Correct 69 ms 4596 KB Output is correct
43 Correct 62 ms 4588 KB Output is correct
44 Correct 77 ms 4588 KB Output is correct
45 Correct 72 ms 4588 KB Output is correct
46 Correct 74 ms 4596 KB Output is correct
47 Correct 66 ms 4592 KB Output is correct
48 Correct 79 ms 4596 KB Output is correct
49 Correct 74 ms 4588 KB Output is correct
50 Correct 76 ms 4564 KB Output is correct
51 Correct 641 ms 33348 KB Output is correct
52 Correct 640 ms 33620 KB Output is correct
53 Correct 791 ms 33472 KB Output is correct
54 Correct 76 ms 4588 KB Output is correct
55 Correct 58 ms 4584 KB Output is correct
56 Correct 192 ms 16980 KB Output is correct
57 Correct 5 ms 384 KB Output is correct
58 Correct 72 ms 4580 KB Output is correct
59 Correct 76 ms 4588 KB Output is correct
60 Correct 871 ms 33344 KB Output is correct
61 Correct 73 ms 4588 KB Output is correct
62 Correct 78 ms 4596 KB Output is correct
63 Correct 86 ms 4596 KB Output is correct
64 Correct 74 ms 4716 KB Output is correct
65 Correct 69 ms 4588 KB Output is correct
66 Correct 72 ms 4584 KB Output is correct
67 Correct 70 ms 4596 KB Output is correct
68 Correct 68 ms 4584 KB Output is correct
69 Correct 78 ms 4588 KB Output is correct
70 Correct 738 ms 33344 KB Output is correct
71 Correct 75 ms 4588 KB Output is correct
72 Correct 600 ms 33344 KB Output is correct
73 Correct 637 ms 33344 KB Output is correct
74 Correct 4 ms 384 KB Output is correct
75 Correct 5 ms 384 KB Output is correct
76 Correct 5 ms 384 KB Output is correct
77 Correct 5 ms 384 KB Output is correct
78 Correct 5 ms 384 KB Output is correct
79 Correct 10 ms 1408 KB Output is correct
80 Correct 815 ms 39616 KB Output is correct
81 Correct 904 ms 39616 KB Output is correct
82 Correct 744 ms 39616 KB Output is correct
83 Correct 771 ms 41112 KB Output is correct
84 Correct 750 ms 45892 KB Output is correct
85 Correct 784 ms 39360 KB Output is correct
86 Correct 211 ms 26708 KB Output is correct
87 Correct 5 ms 384 KB Output is correct