답안 #265284

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
265284 2020-08-14T14:49:39 Z Hideo 이상한 기계 (APIO19_strange_device) C++11
100 / 100
584 ms 44668 KB
//1610612741, 1000000007
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

#define all(s) s.begin(), s.end()
#define ok puts("ok")
#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >
#define pii pair < int, pi >
#define next next123
#define left left123

const int N = 1e6 + 7;
const int INF = 1e9 + 7;

int n;
ll A, B, p, ans;
ll bound = 1e18;
bool trigger = false;

vector < pair < ll, ll > > s;

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> A >> B;
    p = A / __gcd(B + 1, A);
    if (B > bound / p)
        p = bound;
    else
        p *= B;
    for (int i = 1; i <= n; i++){
        ll l, r;
        cin >> l >> r;
        if (r - l + 1 >= p)
            trigger = true;
        l %= p;
        r %= p;
        if (l > r){
            s.pb({l, p - 1});
            s.pb({0, r});
        }
        else
            s.pb({l, r});
    }
    if (trigger){
        cout << p;
        return 0;
    }
    sort(all(s));
    ll r = -1;
    for (auto it : s){
        if (r < it.fr)
            r = it.fr - 1;
        ans += max(0LL, it.sc - r);
        r = max(r, it.sc);
    }
    cout << ans << endl;
}

Compilation message

strange_device.cpp:34:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   34 | main(){
      |      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 6 ms 1152 KB Output is correct
3 Correct 6 ms 1152 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 1152 KB Output is correct
17 Correct 56 ms 5736 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 363 ms 34100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 475 ms 27092 KB Output is correct
3 Correct 489 ms 26708 KB Output is correct
4 Correct 459 ms 27344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 475 ms 27092 KB Output is correct
3 Correct 489 ms 26708 KB Output is correct
4 Correct 459 ms 27344 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 475 ms 27164 KB Output is correct
7 Correct 543 ms 27476 KB Output is correct
8 Correct 487 ms 27480 KB Output is correct
9 Correct 535 ms 27348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 475 ms 27092 KB Output is correct
3 Correct 489 ms 26708 KB Output is correct
4 Correct 459 ms 27344 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 46 ms 5748 KB Output is correct
7 Correct 51 ms 5740 KB Output is correct
8 Correct 55 ms 5740 KB Output is correct
9 Correct 59 ms 5740 KB Output is correct
10 Correct 49 ms 5756 KB Output is correct
11 Correct 57 ms 5736 KB Output is correct
12 Correct 46 ms 5740 KB Output is correct
13 Correct 56 ms 5736 KB Output is correct
14 Correct 47 ms 5792 KB Output is correct
15 Correct 49 ms 5780 KB Output is correct
16 Correct 48 ms 5740 KB Output is correct
17 Correct 46 ms 5736 KB Output is correct
18 Correct 494 ms 23380 KB Output is correct
19 Correct 463 ms 27740 KB Output is correct
20 Correct 547 ms 27876 KB Output is correct
21 Correct 49 ms 5740 KB Output is correct
22 Correct 47 ms 5704 KB Output is correct
23 Correct 163 ms 18528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 52 ms 5740 KB Output is correct
3 Correct 63 ms 5736 KB Output is correct
4 Correct 584 ms 23380 KB Output is correct
5 Correct 50 ms 5736 KB Output is correct
6 Correct 56 ms 5736 KB Output is correct
7 Correct 49 ms 5740 KB Output is correct
8 Correct 49 ms 5808 KB Output is correct
9 Correct 48 ms 5748 KB Output is correct
10 Correct 48 ms 5912 KB Output is correct
11 Correct 51 ms 5876 KB Output is correct
12 Correct 53 ms 5740 KB Output is correct
13 Correct 48 ms 5868 KB Output is correct
14 Correct 492 ms 23508 KB Output is correct
15 Correct 52 ms 5740 KB Output is correct
16 Correct 461 ms 30400 KB Output is correct
17 Correct 461 ms 44668 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 6 ms 1152 KB Output is correct
3 Correct 6 ms 1152 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 1152 KB Output is correct
17 Correct 56 ms 5736 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 363 ms 34100 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 475 ms 27092 KB Output is correct
31 Correct 489 ms 26708 KB Output is correct
32 Correct 459 ms 27344 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 475 ms 27164 KB Output is correct
35 Correct 543 ms 27476 KB Output is correct
36 Correct 487 ms 27480 KB Output is correct
37 Correct 535 ms 27348 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 46 ms 5748 KB Output is correct
40 Correct 51 ms 5740 KB Output is correct
41 Correct 55 ms 5740 KB Output is correct
42 Correct 59 ms 5740 KB Output is correct
43 Correct 49 ms 5756 KB Output is correct
44 Correct 57 ms 5736 KB Output is correct
45 Correct 46 ms 5740 KB Output is correct
46 Correct 56 ms 5736 KB Output is correct
47 Correct 47 ms 5792 KB Output is correct
48 Correct 49 ms 5780 KB Output is correct
49 Correct 48 ms 5740 KB Output is correct
50 Correct 46 ms 5736 KB Output is correct
51 Correct 494 ms 23380 KB Output is correct
52 Correct 463 ms 27740 KB Output is correct
53 Correct 547 ms 27876 KB Output is correct
54 Correct 49 ms 5740 KB Output is correct
55 Correct 47 ms 5704 KB Output is correct
56 Correct 163 ms 18528 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 52 ms 5740 KB Output is correct
59 Correct 63 ms 5736 KB Output is correct
60 Correct 584 ms 23380 KB Output is correct
61 Correct 50 ms 5736 KB Output is correct
62 Correct 56 ms 5736 KB Output is correct
63 Correct 49 ms 5740 KB Output is correct
64 Correct 49 ms 5808 KB Output is correct
65 Correct 48 ms 5748 KB Output is correct
66 Correct 48 ms 5912 KB Output is correct
67 Correct 51 ms 5876 KB Output is correct
68 Correct 53 ms 5740 KB Output is correct
69 Correct 48 ms 5868 KB Output is correct
70 Correct 492 ms 23508 KB Output is correct
71 Correct 52 ms 5740 KB Output is correct
72 Correct 461 ms 30400 KB Output is correct
73 Correct 461 ms 44668 KB Output is correct
74 Correct 1 ms 384 KB Output is correct
75 Correct 1 ms 384 KB Output is correct
76 Correct 1 ms 384 KB Output is correct
77 Correct 1 ms 384 KB Output is correct
78 Correct 1 ms 384 KB Output is correct
79 Correct 7 ms 1152 KB Output is correct
80 Correct 563 ms 27232 KB Output is correct
81 Correct 537 ms 22720 KB Output is correct
82 Correct 506 ms 25408 KB Output is correct
83 Correct 561 ms 29248 KB Output is correct
84 Correct 505 ms 31624 KB Output is correct
85 Correct 515 ms 32820 KB Output is correct
86 Correct 146 ms 18528 KB Output is correct
87 Correct 1 ms 384 KB Output is correct