답안 #134049

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
134049 2019-07-22T02:13:00 Z ksmzzang2003 이상한 기계 (APIO19_strange_device) C++17
100 / 100
728 ms 17824 KB
#define DEBUG
// #define FASTIO
 
#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
 
#define F first
#define S second 
#define pb push_back
#define endl "\n"
 
#ifdef FASTIO
 
#define pr(x) printf("%d", x)
#define ps    printf(" ")
#define endc  printf("\n")
#define pl(x) printf("%lld", x)
#define pf(x) printf("%lf", x)
#define sc(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define sf(x) scanf("%lf", &x)
#define IOS 
 
#endif
 
#ifndef FASTIO
    #define IOS { ios :: sync_with_stdio(false); cin.tie(0); }
#endif
 
#ifdef DEBUG
    #define dbg(s) {s;}
#endif
 
#ifndef DEBUG
    #define dbg(s)
#endif
 
using namespace std;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int grand(int x) { // from [0, n-1]
    return uniform_int_distribution<int>(0, x - 1)(rng);
}
 
#define int ll
#define i32 int32_t
#define all(v) (v).begin(),(v).end()
 
typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
 
inline string ps(pii z) {
    stringstream ss; ss << "[" << z.F << ", " << z.S << "]";
    return ss.str();
}
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
} 
 
const ll mod = 1e9 + 7;
 
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
}
 
const int maxn = 1e6 + 7;
 
const ll inf = 1e18 + 7;
 
vector < pii > v;
 
i32 main() {
    //freopen("<file>.in", "r", stdin);
    //freopen("<file>.out", "w", stdout);
 
    IOS;
    
    int n, A, B; cin >> n >> A >> B;
    int g = gcd(A, B + 1); A /= g;
    if (A >= inf / B) A = inf;
    else A *= B;
 
    for (int j = 1; j <= n; j++) {
        int l, r; cin >> l >> r;
        if (r - l >= A) {
            cout << A << endl; return 0;
        }
        if (l <= A * (r / A)) {
            v.pb({0, r % A});
            if (l < A * (r / A))
                v.pb({l % A, A - 1});
        } else {
            v.pb({l % A, r % A});
        }
    }
 
    sort(all(v));
    
    int ans = 0;
 
    for (int j = 0; j < v.size(); ) {
        int i = j; pii ci = v[j];
        while (i + 1 < v.size() && v[i + 1].F <= ci.S) {
            i++; ci.S = max(ci.S, v[i].S);
        }
        j = i + 1;
        ans += ci.S - ci.F + 1;
    }
    cout << ans << endl;
}

Compilation message

strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:137:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j < v.size(); ) {
                     ~~^~~~~~~~~~
strange_device.cpp:139:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while (i + 1 < v.size() && v[i + 1].F <= ci.S) {
                ~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 1016 KB Output is correct
3 Correct 8 ms 1016 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 292 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 300 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 252 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 8 ms 1016 KB Output is correct
17 Correct 67 ms 3080 KB Output is correct
18 Correct 2 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 3 ms 476 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 466 ms 17392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 603 ms 17408 KB Output is correct
3 Correct 608 ms 17404 KB Output is correct
4 Correct 600 ms 17372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 603 ms 17408 KB Output is correct
3 Correct 608 ms 17404 KB Output is correct
4 Correct 600 ms 17372 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 610 ms 17476 KB Output is correct
7 Correct 728 ms 17736 KB Output is correct
8 Correct 606 ms 17740 KB Output is correct
9 Correct 675 ms 17756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 603 ms 17408 KB Output is correct
3 Correct 608 ms 17404 KB Output is correct
4 Correct 600 ms 17372 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 60 ms 3576 KB Output is correct
7 Correct 67 ms 3476 KB Output is correct
8 Correct 63 ms 3440 KB Output is correct
9 Correct 64 ms 3304 KB Output is correct
10 Correct 61 ms 3312 KB Output is correct
11 Correct 63 ms 3308 KB Output is correct
12 Correct 63 ms 3360 KB Output is correct
13 Correct 68 ms 3312 KB Output is correct
14 Correct 61 ms 3248 KB Output is correct
15 Correct 68 ms 3364 KB Output is correct
16 Correct 68 ms 3308 KB Output is correct
17 Correct 64 ms 3312 KB Output is correct
18 Correct 611 ms 17676 KB Output is correct
19 Correct 601 ms 17728 KB Output is correct
20 Correct 661 ms 17648 KB Output is correct
21 Correct 68 ms 3316 KB Output is correct
22 Correct 61 ms 3052 KB Output is correct
23 Correct 194 ms 10372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 66 ms 3312 KB Output is correct
3 Correct 67 ms 3312 KB Output is correct
4 Correct 698 ms 17824 KB Output is correct
5 Correct 66 ms 3308 KB Output is correct
6 Correct 66 ms 3312 KB Output is correct
7 Correct 67 ms 3356 KB Output is correct
8 Correct 68 ms 3288 KB Output is correct
9 Correct 68 ms 3316 KB Output is correct
10 Correct 67 ms 3268 KB Output is correct
11 Correct 67 ms 3308 KB Output is correct
12 Correct 61 ms 3284 KB Output is correct
13 Correct 67 ms 3280 KB Output is correct
14 Correct 660 ms 17492 KB Output is correct
15 Correct 67 ms 3056 KB Output is correct
16 Correct 604 ms 17464 KB Output is correct
17 Correct 594 ms 17416 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 1016 KB Output is correct
3 Correct 8 ms 1016 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 292 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 300 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 252 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 8 ms 1016 KB Output is correct
17 Correct 67 ms 3080 KB Output is correct
18 Correct 2 ms 296 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 380 KB Output is correct
25 Correct 3 ms 476 KB Output is correct
26 Correct 3 ms 348 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 466 ms 17392 KB Output is correct
29 Correct 3 ms 376 KB Output is correct
30 Correct 603 ms 17408 KB Output is correct
31 Correct 608 ms 17404 KB Output is correct
32 Correct 600 ms 17372 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 610 ms 17476 KB Output is correct
35 Correct 728 ms 17736 KB Output is correct
36 Correct 606 ms 17740 KB Output is correct
37 Correct 675 ms 17756 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 60 ms 3576 KB Output is correct
40 Correct 67 ms 3476 KB Output is correct
41 Correct 63 ms 3440 KB Output is correct
42 Correct 64 ms 3304 KB Output is correct
43 Correct 61 ms 3312 KB Output is correct
44 Correct 63 ms 3308 KB Output is correct
45 Correct 63 ms 3360 KB Output is correct
46 Correct 68 ms 3312 KB Output is correct
47 Correct 61 ms 3248 KB Output is correct
48 Correct 68 ms 3364 KB Output is correct
49 Correct 68 ms 3308 KB Output is correct
50 Correct 64 ms 3312 KB Output is correct
51 Correct 611 ms 17676 KB Output is correct
52 Correct 601 ms 17728 KB Output is correct
53 Correct 661 ms 17648 KB Output is correct
54 Correct 68 ms 3316 KB Output is correct
55 Correct 61 ms 3052 KB Output is correct
56 Correct 194 ms 10372 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 66 ms 3312 KB Output is correct
59 Correct 67 ms 3312 KB Output is correct
60 Correct 698 ms 17824 KB Output is correct
61 Correct 66 ms 3308 KB Output is correct
62 Correct 66 ms 3312 KB Output is correct
63 Correct 67 ms 3356 KB Output is correct
64 Correct 68 ms 3288 KB Output is correct
65 Correct 68 ms 3316 KB Output is correct
66 Correct 67 ms 3268 KB Output is correct
67 Correct 67 ms 3308 KB Output is correct
68 Correct 61 ms 3284 KB Output is correct
69 Correct 67 ms 3280 KB Output is correct
70 Correct 660 ms 17492 KB Output is correct
71 Correct 67 ms 3056 KB Output is correct
72 Correct 604 ms 17464 KB Output is correct
73 Correct 594 ms 17416 KB Output is correct
74 Correct 2 ms 376 KB Output is correct
75 Correct 2 ms 376 KB Output is correct
76 Correct 2 ms 376 KB Output is correct
77 Correct 2 ms 380 KB Output is correct
78 Correct 2 ms 376 KB Output is correct
79 Correct 8 ms 812 KB Output is correct
80 Correct 699 ms 17036 KB Output is correct
81 Correct 706 ms 17292 KB Output is correct
82 Correct 664 ms 17392 KB Output is correct
83 Correct 652 ms 17328 KB Output is correct
84 Correct 646 ms 17360 KB Output is correct
85 Correct 655 ms 17424 KB Output is correct
86 Correct 191 ms 9064 KB Output is correct
87 Correct 2 ms 376 KB Output is correct