답안 #374766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
374766 2021-03-08T06:31:59 Z AriaH 이상한 기계 (APIO19_strange_device) C++11
100 / 100
611 ms 53556 KB
/** I can do this all day **/

#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;

typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define SZ(x)			    		(int)x.size()
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);

const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ll inf = 8e18;
const int LOG = 22;
const ld one = 1.;
const ld eps = 1e-12;

ll pw(ll a , ll b, ll M)  { return (!b ? 1 : (b & 1 ? (a * pw(a * a % M, b / 2, M)) % M : pw(a * a % M, b / 2, M))); }

int n;

ll A, B, L;

vector < pll > vec;

int main()
{
	scanf("%d%lld%lld", &n, &A, &B);
	L = A / __gcd(A, B + 1); /// A | t - t2 + (t - t2) / B -> A | (B + 1) * ((t - t2) / B)
	if(one * L * B - one * inf > eps) L = inf;
	else L *= B;
	for(int i = 1; i <= n; i ++)
	{
		ll l, r;
		scanf("%lld%lld", &l, &r);
		if(r - l > L)
		{
			return !printf("%lld", L);
		}
		r %= L, l %= L;
		if(l <= r)
		{
			vec.push_back(Mp(l, r));
		}
		else
		{
			vec.push_back(Mp(l, L - 1));
			vec.push_back(Mp(0, r));
		}
	}
	sort(all(vec));
	ll tot = 0, right = -1;
	for(auto cu : vec)
	{
		right = max(right, cu.F - 1);
		tot += max(0ll, cu.S - right);
		right = max(cu.S, right);
	}
	printf("%lld", tot);
    return 0;
}

/** test corner cases(n = 1?) watch for overflow or minus indices **/

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |  scanf("%d%lld%lld", &n, &A, &B);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |   scanf("%lld%lld", &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 6 ms 1132 KB Output is correct
3 Correct 6 ms 1132 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 1004 KB Output is correct
17 Correct 56 ms 5724 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 386 ms 21468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 521 ms 53300 KB Output is correct
3 Correct 514 ms 53300 KB Output is correct
4 Correct 508 ms 53428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 521 ms 53300 KB Output is correct
3 Correct 514 ms 53300 KB Output is correct
4 Correct 508 ms 53428 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 521 ms 53472 KB Output is correct
7 Correct 520 ms 53300 KB Output is correct
8 Correct 511 ms 53464 KB Output is correct
9 Correct 569 ms 53452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 521 ms 53300 KB Output is correct
3 Correct 514 ms 53300 KB Output is correct
4 Correct 508 ms 53428 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 52 ms 5724 KB Output is correct
7 Correct 54 ms 5724 KB Output is correct
8 Correct 51 ms 5724 KB Output is correct
9 Correct 55 ms 5724 KB Output is correct
10 Correct 51 ms 5852 KB Output is correct
11 Correct 55 ms 5724 KB Output is correct
12 Correct 51 ms 5724 KB Output is correct
13 Correct 55 ms 5864 KB Output is correct
14 Correct 50 ms 5724 KB Output is correct
15 Correct 55 ms 5724 KB Output is correct
16 Correct 60 ms 5748 KB Output is correct
17 Correct 53 ms 5724 KB Output is correct
18 Correct 522 ms 53556 KB Output is correct
19 Correct 514 ms 53300 KB Output is correct
20 Correct 573 ms 53300 KB Output is correct
21 Correct 54 ms 5724 KB Output is correct
22 Correct 51 ms 5724 KB Output is correct
23 Correct 162 ms 18516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 56 ms 5724 KB Output is correct
3 Correct 56 ms 5724 KB Output is correct
4 Correct 611 ms 53460 KB Output is correct
5 Correct 54 ms 5744 KB Output is correct
6 Correct 54 ms 5724 KB Output is correct
7 Correct 54 ms 5724 KB Output is correct
8 Correct 55 ms 5724 KB Output is correct
9 Correct 53 ms 5724 KB Output is correct
10 Correct 53 ms 5724 KB Output is correct
11 Correct 55 ms 5876 KB Output is correct
12 Correct 51 ms 5852 KB Output is correct
13 Correct 54 ms 5724 KB Output is correct
14 Correct 560 ms 53300 KB Output is correct
15 Correct 53 ms 5736 KB Output is correct
16 Correct 526 ms 53332 KB Output is correct
17 Correct 514 ms 53440 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 6 ms 1132 KB Output is correct
3 Correct 6 ms 1132 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 1004 KB Output is correct
17 Correct 56 ms 5724 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 386 ms 21468 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 521 ms 53300 KB Output is correct
31 Correct 514 ms 53300 KB Output is correct
32 Correct 508 ms 53428 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 521 ms 53472 KB Output is correct
35 Correct 520 ms 53300 KB Output is correct
36 Correct 511 ms 53464 KB Output is correct
37 Correct 569 ms 53452 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 52 ms 5724 KB Output is correct
40 Correct 54 ms 5724 KB Output is correct
41 Correct 51 ms 5724 KB Output is correct
42 Correct 55 ms 5724 KB Output is correct
43 Correct 51 ms 5852 KB Output is correct
44 Correct 55 ms 5724 KB Output is correct
45 Correct 51 ms 5724 KB Output is correct
46 Correct 55 ms 5864 KB Output is correct
47 Correct 50 ms 5724 KB Output is correct
48 Correct 55 ms 5724 KB Output is correct
49 Correct 60 ms 5748 KB Output is correct
50 Correct 53 ms 5724 KB Output is correct
51 Correct 522 ms 53556 KB Output is correct
52 Correct 514 ms 53300 KB Output is correct
53 Correct 573 ms 53300 KB Output is correct
54 Correct 54 ms 5724 KB Output is correct
55 Correct 51 ms 5724 KB Output is correct
56 Correct 162 ms 18516 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 56 ms 5724 KB Output is correct
59 Correct 56 ms 5724 KB Output is correct
60 Correct 611 ms 53460 KB Output is correct
61 Correct 54 ms 5744 KB Output is correct
62 Correct 54 ms 5724 KB Output is correct
63 Correct 54 ms 5724 KB Output is correct
64 Correct 55 ms 5724 KB Output is correct
65 Correct 53 ms 5724 KB Output is correct
66 Correct 53 ms 5724 KB Output is correct
67 Correct 55 ms 5876 KB Output is correct
68 Correct 51 ms 5852 KB Output is correct
69 Correct 54 ms 5724 KB Output is correct
70 Correct 560 ms 53300 KB Output is correct
71 Correct 53 ms 5736 KB Output is correct
72 Correct 526 ms 53332 KB Output is correct
73 Correct 514 ms 53440 KB Output is correct
74 Correct 1 ms 364 KB Output is correct
75 Correct 1 ms 364 KB Output is correct
76 Correct 1 ms 364 KB Output is correct
77 Correct 1 ms 364 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 8 ms 1132 KB Output is correct
80 Correct 578 ms 22904 KB Output is correct
81 Correct 574 ms 24392 KB Output is correct
82 Correct 549 ms 24776 KB Output is correct
83 Correct 541 ms 24776 KB Output is correct
84 Correct 561 ms 53300 KB Output is correct
85 Correct 559 ms 53300 KB Output is correct
86 Correct 162 ms 18516 KB Output is correct
87 Correct 1 ms 364 KB Output is correct