답안 #475912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
475912 2021-09-24T12:49:17 Z mat_v 이상한 기계 (APIO19_strange_device) C++14
100 / 100
932 ms 86164 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<ll,ll>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


int n;
ll a,b;
ll brt;
pii niz[1000005];
vector<pii> svi;

void ddj(ll x, ll y){
    svi.pb({x,0});
    svi.pb({y,1});
}

int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> a >> b;
    ll uk = 0;
    ff(i,1,n){
        cin >> niz[i].xx >> niz[i].yy;
        uk += (niz[i].yy - niz[i].xx + 1);
    }
    ll tmp = __gcd(b + 1, a);
    tmp = a / tmp;
    ll sta = LLONG_MAX;
    bool flg = 0;
    if(tmp >= sta/b){
        cout << uk << "\n";
        return 0;
    }
    brt = tmp*b;
    ff(i,1,n){
        if((niz[i].yy - niz[i].xx +1) >= brt){
            cout << brt << "\n";
            return 0;
        }
        if((niz[i].yy%brt) < (niz[i].xx%brt)){
            ddj(niz[i].xx%brt, brt - 1);
            ddj(0, niz[i].yy%brt);
        }
        else ddj(niz[i].xx%brt, niz[i].yy%brt);
    }
    sort(svi.begin(), svi.end());
    int op = 0;
    ll last = -1;
    ll ans = brt;
    for(auto c:svi){

        if(c.yy == 1){
            op--;
            last = c.xx;
            continue;
        }
        else{
            if(op == 0){
                ans -= (c.xx - last);
                ans++;
            }
            last = c.xx;
            op++;
        }
    }
    ans -= (brt - last);
    ans++;
    cout << ans << "\n";



    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
strange_device.cpp:40:5: note: in expansion of macro 'ff'
   40 |     ff(i,1,n){
      |     ^~
strange_device.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
strange_device.cpp:53:5: note: in expansion of macro 'ff'
   53 |     ff(i,1,n){
      |     ^~
strange_device.cpp:47:10: warning: unused variable 'flg' [-Wunused-variable]
   47 |     bool flg = 0;
      |          ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 7 ms 1488 KB Output is correct
3 Correct 7 ms 1372 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 236 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 6 ms 1488 KB Output is correct
17 Correct 78 ms 9728 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 434 ms 48996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 604 ms 52600 KB Output is correct
3 Correct 658 ms 49160 KB Output is correct
4 Correct 762 ms 49344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 604 ms 52600 KB Output is correct
3 Correct 658 ms 49160 KB Output is correct
4 Correct 762 ms 49344 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 653 ms 49356 KB Output is correct
7 Correct 628 ms 49380 KB Output is correct
8 Correct 654 ms 49316 KB Output is correct
9 Correct 801 ms 49324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 604 ms 52600 KB Output is correct
3 Correct 658 ms 49160 KB Output is correct
4 Correct 762 ms 49344 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 56 ms 9844 KB Output is correct
7 Correct 68 ms 9780 KB Output is correct
8 Correct 75 ms 9736 KB Output is correct
9 Correct 74 ms 9788 KB Output is correct
10 Correct 58 ms 9768 KB Output is correct
11 Correct 69 ms 9828 KB Output is correct
12 Correct 56 ms 9932 KB Output is correct
13 Correct 61 ms 9748 KB Output is correct
14 Correct 55 ms 9720 KB Output is correct
15 Correct 65 ms 9772 KB Output is correct
16 Correct 63 ms 9788 KB Output is correct
17 Correct 61 ms 9816 KB Output is correct
18 Correct 625 ms 49356 KB Output is correct
19 Correct 592 ms 49440 KB Output is correct
20 Correct 734 ms 49344 KB Output is correct
21 Correct 67 ms 9792 KB Output is correct
22 Correct 81 ms 9820 KB Output is correct
23 Correct 185 ms 26300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 60 ms 9840 KB Output is correct
3 Correct 60 ms 9728 KB Output is correct
4 Correct 712 ms 49364 KB Output is correct
5 Correct 65 ms 9844 KB Output is correct
6 Correct 82 ms 9816 KB Output is correct
7 Correct 63 ms 9728 KB Output is correct
8 Correct 66 ms 9788 KB Output is correct
9 Correct 63 ms 9808 KB Output is correct
10 Correct 64 ms 9816 KB Output is correct
11 Correct 64 ms 9788 KB Output is correct
12 Correct 55 ms 9740 KB Output is correct
13 Correct 68 ms 9788 KB Output is correct
14 Correct 649 ms 49356 KB Output is correct
15 Correct 61 ms 9784 KB Output is correct
16 Correct 539 ms 49416 KB Output is correct
17 Correct 620 ms 49316 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 7 ms 1488 KB Output is correct
3 Correct 7 ms 1372 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 236 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 6 ms 1488 KB Output is correct
17 Correct 78 ms 9728 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 434 ms 48996 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 604 ms 52600 KB Output is correct
31 Correct 658 ms 49160 KB Output is correct
32 Correct 762 ms 49344 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 653 ms 49356 KB Output is correct
35 Correct 628 ms 49380 KB Output is correct
36 Correct 654 ms 49316 KB Output is correct
37 Correct 801 ms 49324 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 56 ms 9844 KB Output is correct
40 Correct 68 ms 9780 KB Output is correct
41 Correct 75 ms 9736 KB Output is correct
42 Correct 74 ms 9788 KB Output is correct
43 Correct 58 ms 9768 KB Output is correct
44 Correct 69 ms 9828 KB Output is correct
45 Correct 56 ms 9932 KB Output is correct
46 Correct 61 ms 9748 KB Output is correct
47 Correct 55 ms 9720 KB Output is correct
48 Correct 65 ms 9772 KB Output is correct
49 Correct 63 ms 9788 KB Output is correct
50 Correct 61 ms 9816 KB Output is correct
51 Correct 625 ms 49356 KB Output is correct
52 Correct 592 ms 49440 KB Output is correct
53 Correct 734 ms 49344 KB Output is correct
54 Correct 67 ms 9792 KB Output is correct
55 Correct 81 ms 9820 KB Output is correct
56 Correct 185 ms 26300 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 60 ms 9840 KB Output is correct
59 Correct 60 ms 9728 KB Output is correct
60 Correct 712 ms 49364 KB Output is correct
61 Correct 65 ms 9844 KB Output is correct
62 Correct 82 ms 9816 KB Output is correct
63 Correct 63 ms 9728 KB Output is correct
64 Correct 66 ms 9788 KB Output is correct
65 Correct 63 ms 9808 KB Output is correct
66 Correct 64 ms 9816 KB Output is correct
67 Correct 64 ms 9788 KB Output is correct
68 Correct 55 ms 9740 KB Output is correct
69 Correct 68 ms 9788 KB Output is correct
70 Correct 649 ms 49356 KB Output is correct
71 Correct 61 ms 9784 KB Output is correct
72 Correct 539 ms 49416 KB Output is correct
73 Correct 620 ms 49316 KB Output is correct
74 Correct 1 ms 204 KB Output is correct
75 Correct 1 ms 204 KB Output is correct
76 Correct 1 ms 204 KB Output is correct
77 Correct 1 ms 204 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 6 ms 1488 KB Output is correct
80 Correct 757 ms 86040 KB Output is correct
81 Correct 744 ms 86128 KB Output is correct
82 Correct 721 ms 86108 KB Output is correct
83 Correct 932 ms 85992 KB Output is correct
84 Correct 721 ms 86124 KB Output is correct
85 Correct 703 ms 86164 KB Output is correct
86 Correct 171 ms 34668 KB Output is correct
87 Correct 1 ms 332 KB Output is correct