답안 #597802

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
597802 2022-07-16T22:26:37 Z Ozy 이상한 기계 (APIO19_strange_device) C++17
100 / 100
556 ms 40192 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli unsigned long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)

#define LIM (1ll << 60)

lli a,b,n,cont,x,y,mult,ini,res,k;
vector<pair<lli,lli> > orden;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> a >> b;
    k = __gcd(a,b+1);
    //debug(k);
    k = a/k;

    if (LIM/k < b) mult = LIM;
    else mult = k*b;

    rep(i,1,n) {
        cin >> x >> y;

        if (x == y) {
            x %= mult;
            orden.push_back({x,1});
            orden.push_back({x,2});
            continue;
        }

        k = y-x;
        if  (k >= mult) {
            orden.push_back({0,1});
            orden.push_back({mult-1,2});
            continue;
        }

        x %= mult;
        y %= mult;

        if (x >= y) {
            orden.push_back({0,1});
            orden.push_back({mult-1,2});
        }
        orden.push_back({x,1});
        orden.push_back({y,2});
    }

    sort(orden.begin(), orden.end());

    ini = -1;
    cont = 0;
    res = 0;
    for (auto act:orden) {

        if (act.second == 1) {
            cont++;
            if (ini == -1) ini = act.first;
        }
        else cont--;

        if (cont == 0) {
            res += (act.first - ini) + 1;
            ini = -1;
        }
    }

    cout << res;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:7:39: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
    7 | #define rep(i,a,b) for(int i = (a); i <= (b); i++)
      |                                       ^
strange_device.cpp:28:5: note: in expansion of macro 'rep'
   28 |     rep(i,1,n) {
      |     ^~~
strange_device.cpp:65:21: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'int' [-Wsign-compare]
   65 |             if (ini == -1) ini = act.first;
      |                 ~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 856 KB Output is correct
3 Correct 7 ms 924 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 856 KB Output is correct
17 Correct 51 ms 4556 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 0 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 0 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 305 ms 33224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 456 ms 33172 KB Output is correct
3 Correct 458 ms 33304 KB Output is correct
4 Correct 426 ms 33200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 456 ms 33172 KB Output is correct
3 Correct 458 ms 33304 KB Output is correct
4 Correct 426 ms 33200 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 448 ms 33424 KB Output is correct
7 Correct 428 ms 33276 KB Output is correct
8 Correct 429 ms 33224 KB Output is correct
9 Correct 510 ms 33176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 456 ms 33172 KB Output is correct
3 Correct 458 ms 33304 KB Output is correct
4 Correct 426 ms 33200 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 41 ms 4536 KB Output is correct
7 Correct 44 ms 4564 KB Output is correct
8 Correct 42 ms 4488 KB Output is correct
9 Correct 43 ms 4532 KB Output is correct
10 Correct 39 ms 4472 KB Output is correct
11 Correct 43 ms 4556 KB Output is correct
12 Correct 42 ms 4472 KB Output is correct
13 Correct 48 ms 4556 KB Output is correct
14 Correct 43 ms 4548 KB Output is correct
15 Correct 52 ms 4556 KB Output is correct
16 Correct 47 ms 4504 KB Output is correct
17 Correct 41 ms 4556 KB Output is correct
18 Correct 451 ms 33176 KB Output is correct
19 Correct 424 ms 33188 KB Output is correct
20 Correct 525 ms 33344 KB Output is correct
21 Correct 49 ms 4468 KB Output is correct
22 Correct 37 ms 4560 KB Output is correct
23 Correct 119 ms 16864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 49 ms 4440 KB Output is correct
3 Correct 46 ms 4556 KB Output is correct
4 Correct 536 ms 33224 KB Output is correct
5 Correct 48 ms 4544 KB Output is correct
6 Correct 46 ms 4464 KB Output is correct
7 Correct 45 ms 4548 KB Output is correct
8 Correct 48 ms 4560 KB Output is correct
9 Correct 47 ms 4488 KB Output is correct
10 Correct 49 ms 4556 KB Output is correct
11 Correct 46 ms 4460 KB Output is correct
12 Correct 41 ms 4540 KB Output is correct
13 Correct 50 ms 4460 KB Output is correct
14 Correct 517 ms 33224 KB Output is correct
15 Correct 49 ms 4452 KB Output is correct
16 Correct 414 ms 33280 KB Output is correct
17 Correct 444 ms 33184 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 5 ms 856 KB Output is correct
3 Correct 7 ms 924 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 856 KB Output is correct
17 Correct 51 ms 4556 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 0 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 0 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 305 ms 33224 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 456 ms 33172 KB Output is correct
31 Correct 458 ms 33304 KB Output is correct
32 Correct 426 ms 33200 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 448 ms 33424 KB Output is correct
35 Correct 428 ms 33276 KB Output is correct
36 Correct 429 ms 33224 KB Output is correct
37 Correct 510 ms 33176 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 41 ms 4536 KB Output is correct
40 Correct 44 ms 4564 KB Output is correct
41 Correct 42 ms 4488 KB Output is correct
42 Correct 43 ms 4532 KB Output is correct
43 Correct 39 ms 4472 KB Output is correct
44 Correct 43 ms 4556 KB Output is correct
45 Correct 42 ms 4472 KB Output is correct
46 Correct 48 ms 4556 KB Output is correct
47 Correct 43 ms 4548 KB Output is correct
48 Correct 52 ms 4556 KB Output is correct
49 Correct 47 ms 4504 KB Output is correct
50 Correct 41 ms 4556 KB Output is correct
51 Correct 451 ms 33176 KB Output is correct
52 Correct 424 ms 33188 KB Output is correct
53 Correct 525 ms 33344 KB Output is correct
54 Correct 49 ms 4468 KB Output is correct
55 Correct 37 ms 4560 KB Output is correct
56 Correct 119 ms 16864 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 49 ms 4440 KB Output is correct
59 Correct 46 ms 4556 KB Output is correct
60 Correct 536 ms 33224 KB Output is correct
61 Correct 48 ms 4544 KB Output is correct
62 Correct 46 ms 4464 KB Output is correct
63 Correct 45 ms 4548 KB Output is correct
64 Correct 48 ms 4560 KB Output is correct
65 Correct 47 ms 4488 KB Output is correct
66 Correct 49 ms 4556 KB Output is correct
67 Correct 46 ms 4460 KB Output is correct
68 Correct 41 ms 4540 KB Output is correct
69 Correct 50 ms 4460 KB Output is correct
70 Correct 517 ms 33224 KB Output is correct
71 Correct 49 ms 4452 KB Output is correct
72 Correct 414 ms 33280 KB Output is correct
73 Correct 444 ms 33184 KB Output is correct
74 Correct 0 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 0 ms 212 KB Output is correct
79 Correct 4 ms 1240 KB Output is correct
80 Correct 550 ms 40128 KB Output is correct
81 Correct 551 ms 40080 KB Output is correct
82 Correct 556 ms 40104 KB Output is correct
83 Correct 522 ms 40064 KB Output is correct
84 Correct 519 ms 40108 KB Output is correct
85 Correct 515 ms 40192 KB Output is correct
86 Correct 132 ms 26656 KB Output is correct
87 Correct 1 ms 212 KB Output is correct