답안 #710527

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
710527 2023-03-15T10:21:12 Z Ronin13 이상한 기계 (APIO19_strange_device) C++14
100 / 100
1586 ms 86572 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax = 1000001;


int main(){
    int n; cin >> n;
    ll a, b; cin >> a >> b;
    ll l[n + 1], r[n + 1];
    for(int i = 1; i <= n; i++)
        cin >> l[i] >> r[i];
    ll o = 2e18;
    if(o / a < b + 1){
        ll s = 0;
        for(int i = 1; i <= n; i++)
            s += (r[i] - l[i] + 1);
        cout << s << "\n";
        return 0;
    }
    ll x = __gcd(a, b + 1);
    x = a / x * b;
    vector <pll> vec;
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        if(l[i] / x == r[i] / x){
            vec.pb({l[i] % x, 1});
            vec.pb({r[i] % x + 1, -1});
        }
        else{
            vec.pb({l[i] % x, 1});
            vec.pb({x, -1});
            vec.pb({0, 1});
            vec.pb({r[i] % x + 1, -1});
        }
    }
    sort(vec.begin(), vec.end());
    ll ans = 0;
    ll last = -1;
    for(auto to : vec){
        ll x = to.f, y = to.s;
        if(cnt == 0){
            last = x;
        }
        cnt += y;
        if(cnt == 0){
            ans += x - last;
        }
    }
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 17 ms 1440 KB Output is correct
3 Correct 15 ms 1464 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 15 ms 1360 KB Output is correct
17 Correct 160 ms 9748 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 3 ms 456 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 991 ms 74004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1405 ms 86048 KB Output is correct
3 Correct 1418 ms 86312 KB Output is correct
4 Correct 1392 ms 86080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1405 ms 86048 KB Output is correct
3 Correct 1418 ms 86312 KB Output is correct
4 Correct 1392 ms 86080 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1424 ms 86316 KB Output is correct
7 Correct 1405 ms 86572 KB Output is correct
8 Correct 1391 ms 86456 KB Output is correct
9 Correct 1469 ms 86204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1405 ms 86048 KB Output is correct
3 Correct 1418 ms 86312 KB Output is correct
4 Correct 1392 ms 86080 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 137 ms 9752 KB Output is correct
7 Correct 145 ms 9756 KB Output is correct
8 Correct 137 ms 9876 KB Output is correct
9 Correct 138 ms 9876 KB Output is correct
10 Correct 132 ms 9788 KB Output is correct
11 Correct 137 ms 9768 KB Output is correct
12 Correct 137 ms 9760 KB Output is correct
13 Correct 145 ms 9748 KB Output is correct
14 Correct 133 ms 9748 KB Output is correct
15 Correct 144 ms 9876 KB Output is correct
16 Correct 149 ms 9756 KB Output is correct
17 Correct 140 ms 9756 KB Output is correct
18 Correct 1434 ms 86112 KB Output is correct
19 Correct 1410 ms 86316 KB Output is correct
20 Correct 1486 ms 86256 KB Output is correct
21 Correct 146 ms 9748 KB Output is correct
22 Correct 132 ms 9760 KB Output is correct
23 Correct 444 ms 34776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 147 ms 9728 KB Output is correct
3 Correct 144 ms 9760 KB Output is correct
4 Correct 1586 ms 85948 KB Output is correct
5 Correct 155 ms 9752 KB Output is correct
6 Correct 144 ms 9752 KB Output is correct
7 Correct 145 ms 9756 KB Output is correct
8 Correct 155 ms 9748 KB Output is correct
9 Correct 148 ms 9748 KB Output is correct
10 Correct 149 ms 9752 KB Output is correct
11 Correct 171 ms 9744 KB Output is correct
12 Correct 139 ms 9748 KB Output is correct
13 Correct 145 ms 9748 KB Output is correct
14 Correct 1526 ms 85872 KB Output is correct
15 Correct 157 ms 9788 KB Output is correct
16 Correct 1412 ms 86036 KB Output is correct
17 Correct 1434 ms 86204 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 17 ms 1440 KB Output is correct
3 Correct 15 ms 1464 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 15 ms 1360 KB Output is correct
17 Correct 160 ms 9748 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 296 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 3 ms 456 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 991 ms 74004 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1405 ms 86048 KB Output is correct
31 Correct 1418 ms 86312 KB Output is correct
32 Correct 1392 ms 86080 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1424 ms 86316 KB Output is correct
35 Correct 1405 ms 86572 KB Output is correct
36 Correct 1391 ms 86456 KB Output is correct
37 Correct 1469 ms 86204 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 137 ms 9752 KB Output is correct
40 Correct 145 ms 9756 KB Output is correct
41 Correct 137 ms 9876 KB Output is correct
42 Correct 138 ms 9876 KB Output is correct
43 Correct 132 ms 9788 KB Output is correct
44 Correct 137 ms 9768 KB Output is correct
45 Correct 137 ms 9760 KB Output is correct
46 Correct 145 ms 9748 KB Output is correct
47 Correct 133 ms 9748 KB Output is correct
48 Correct 144 ms 9876 KB Output is correct
49 Correct 149 ms 9756 KB Output is correct
50 Correct 140 ms 9756 KB Output is correct
51 Correct 1434 ms 86112 KB Output is correct
52 Correct 1410 ms 86316 KB Output is correct
53 Correct 1486 ms 86256 KB Output is correct
54 Correct 146 ms 9748 KB Output is correct
55 Correct 132 ms 9760 KB Output is correct
56 Correct 444 ms 34776 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 147 ms 9728 KB Output is correct
59 Correct 144 ms 9760 KB Output is correct
60 Correct 1586 ms 85948 KB Output is correct
61 Correct 155 ms 9752 KB Output is correct
62 Correct 144 ms 9752 KB Output is correct
63 Correct 145 ms 9756 KB Output is correct
64 Correct 155 ms 9748 KB Output is correct
65 Correct 148 ms 9748 KB Output is correct
66 Correct 149 ms 9752 KB Output is correct
67 Correct 171 ms 9744 KB Output is correct
68 Correct 139 ms 9748 KB Output is correct
69 Correct 145 ms 9748 KB Output is correct
70 Correct 1526 ms 85872 KB Output is correct
71 Correct 157 ms 9788 KB Output is correct
72 Correct 1412 ms 86036 KB Output is correct
73 Correct 1434 ms 86204 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 1 ms 212 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 14 ms 1360 KB Output is correct
80 Correct 1539 ms 85912 KB Output is correct
81 Correct 1556 ms 85872 KB Output is correct
82 Correct 1497 ms 85656 KB Output is correct
83 Correct 1543 ms 85464 KB Output is correct
84 Correct 1470 ms 85308 KB Output is correct
85 Correct 1476 ms 85212 KB Output is correct
86 Correct 443 ms 34628 KB Output is correct
87 Correct 1 ms 212 KB Output is correct