답안 #568716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
568716 2022-05-26T06:04:55 Z joshjms 이상한 기계 (APIO19_strange_device) C++17
100 / 100
657 ms 50072 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define debug(x) cout << #x << " => " << x << "\n";

const long long mod = 1e9 + 7;
const long long MAX = 1e18;

int n, a, b, L[1000005], R[1000005], s, m;
vector <pair<int,int>> ls;
int cnt, prv, ans;

void solve () {
    cin >> n >> a >> b;

    for(int i = 1; i <= n; i++) {
        cin >> L[i] >> R[i];
        s += R[i] - L[i] + 1;
    }

    if(MAX / a < b) {
        cout << s << "\n";
        return;
    }

    m = a * b / __gcd(a, b + 1);

    for(int i = 1; i <= n; i++) {
        if(R[i] - L[i] + 1 >= m) {
            cout << m << "\n";
            return;
        }
    }

    for(int i = 1; i <= n; i++) {
        L[i] %= m;
        R[i] %= m;

        if(R[i] < L[i]) {
            ls.pb({L[i], 0});
            ls.pb({m, 1});
            ls.pb({0, 0});
            ls.pb({R[i] + 1, 1});
        }
        else {
            ls.pb({L[i], 0});
            ls.pb({R[i] + 1, 1});
        }
    }
    
    sort(ls.begin(), ls.end());
    cnt = 0, prv = -1;

    // for(auto i : ls) cout << i.fi << " ";
    // cout << "\n";

    for(int i = 0; i < ls.size(); i++) {
        if(ls[i].se == 0) cnt++;
        else cnt--;

        if(i < ls.size() - 1 && ls[i].fi == ls[i + 1].fi) continue;

        if(cnt > 0 && prv == -1) {prv = ls[i].fi;}
        if(cnt == 0 && prv != -1) {ans += ls[i].fi - prv; prv = -1;}
    }

    if(prv != -1) ans += m - prv;

    cout << ans << "\n";

}

signed main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}

Compilation message

strange_device.cpp: In function 'void solve()':
strange_device.cpp:62:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i = 0; i < ls.size(); i++) {
      |                    ~~^~~~~~~~~~~
strange_device.cpp:66:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         if(i < ls.size() - 1 && ls[i].fi == ls[i + 1].fi) continue;
      |            ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 6 ms 1520 KB Output is correct
3 Correct 6 ms 1504 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 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 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 8 ms 1496 KB Output is correct
17 Correct 61 ms 6476 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 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 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 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 365 ms 49404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 523 ms 50072 KB Output is correct
3 Correct 556 ms 49192 KB Output is correct
4 Correct 483 ms 48872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 523 ms 50072 KB Output is correct
3 Correct 556 ms 49192 KB Output is correct
4 Correct 483 ms 48872 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 540 ms 48992 KB Output is correct
7 Correct 515 ms 49060 KB Output is correct
8 Correct 586 ms 48904 KB Output is correct
9 Correct 643 ms 48924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 523 ms 50072 KB Output is correct
3 Correct 556 ms 49192 KB Output is correct
4 Correct 483 ms 48872 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 51 ms 6056 KB Output is correct
7 Correct 54 ms 6112 KB Output is correct
8 Correct 47 ms 6096 KB Output is correct
9 Correct 50 ms 6116 KB Output is correct
10 Correct 50 ms 6084 KB Output is correct
11 Correct 66 ms 6080 KB Output is correct
12 Correct 46 ms 6084 KB Output is correct
13 Correct 54 ms 6148 KB Output is correct
14 Correct 48 ms 6048 KB Output is correct
15 Correct 62 ms 6116 KB Output is correct
16 Correct 55 ms 6084 KB Output is correct
17 Correct 50 ms 6152 KB Output is correct
18 Correct 513 ms 48896 KB Output is correct
19 Correct 512 ms 48876 KB Output is correct
20 Correct 644 ms 48928 KB Output is correct
21 Correct 61 ms 6084 KB Output is correct
22 Correct 51 ms 6084 KB Output is correct
23 Correct 146 ms 22216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 56 ms 6032 KB Output is correct
3 Correct 66 ms 6116 KB Output is correct
4 Correct 629 ms 48972 KB Output is correct
5 Correct 54 ms 6064 KB Output is correct
6 Correct 53 ms 6040 KB Output is correct
7 Correct 53 ms 6084 KB Output is correct
8 Correct 66 ms 6040 KB Output is correct
9 Correct 53 ms 6084 KB Output is correct
10 Correct 60 ms 6172 KB Output is correct
11 Correct 58 ms 6140 KB Output is correct
12 Correct 53 ms 6056 KB Output is correct
13 Correct 59 ms 6096 KB Output is correct
14 Correct 631 ms 48908 KB Output is correct
15 Correct 57 ms 6160 KB Output is correct
16 Correct 517 ms 48988 KB Output is correct
17 Correct 531 ms 49072 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 6 ms 1520 KB Output is correct
3 Correct 6 ms 1504 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 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 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 8 ms 1496 KB Output is correct
17 Correct 61 ms 6476 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 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 365 ms 49404 KB Output is correct
29 Correct 1 ms 328 KB Output is correct
30 Correct 523 ms 50072 KB Output is correct
31 Correct 556 ms 49192 KB Output is correct
32 Correct 483 ms 48872 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 540 ms 48992 KB Output is correct
35 Correct 515 ms 49060 KB Output is correct
36 Correct 586 ms 48904 KB Output is correct
37 Correct 643 ms 48924 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 51 ms 6056 KB Output is correct
40 Correct 54 ms 6112 KB Output is correct
41 Correct 47 ms 6096 KB Output is correct
42 Correct 50 ms 6116 KB Output is correct
43 Correct 50 ms 6084 KB Output is correct
44 Correct 66 ms 6080 KB Output is correct
45 Correct 46 ms 6084 KB Output is correct
46 Correct 54 ms 6148 KB Output is correct
47 Correct 48 ms 6048 KB Output is correct
48 Correct 62 ms 6116 KB Output is correct
49 Correct 55 ms 6084 KB Output is correct
50 Correct 50 ms 6152 KB Output is correct
51 Correct 513 ms 48896 KB Output is correct
52 Correct 512 ms 48876 KB Output is correct
53 Correct 644 ms 48928 KB Output is correct
54 Correct 61 ms 6084 KB Output is correct
55 Correct 51 ms 6084 KB Output is correct
56 Correct 146 ms 22216 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 56 ms 6032 KB Output is correct
59 Correct 66 ms 6116 KB Output is correct
60 Correct 629 ms 48972 KB Output is correct
61 Correct 54 ms 6064 KB Output is correct
62 Correct 53 ms 6040 KB Output is correct
63 Correct 53 ms 6084 KB Output is correct
64 Correct 66 ms 6040 KB Output is correct
65 Correct 53 ms 6084 KB Output is correct
66 Correct 60 ms 6172 KB Output is correct
67 Correct 58 ms 6140 KB Output is correct
68 Correct 53 ms 6056 KB Output is correct
69 Correct 59 ms 6096 KB Output is correct
70 Correct 631 ms 48908 KB Output is correct
71 Correct 57 ms 6160 KB Output is correct
72 Correct 517 ms 48988 KB Output is correct
73 Correct 531 ms 49072 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 8 ms 1508 KB Output is correct
80 Correct 650 ms 49252 KB Output is correct
81 Correct 657 ms 49308 KB Output is correct
82 Correct 618 ms 49272 KB Output is correct
83 Correct 617 ms 49316 KB Output is correct
84 Correct 614 ms 49244 KB Output is correct
85 Correct 577 ms 49388 KB Output is correct
86 Correct 167 ms 33212 KB Output is correct
87 Correct 1 ms 340 KB Output is correct