답안 #764729

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
764729 2023-06-24T02:31:21 Z KN200711 이상한 기계 (APIO19_strange_device) C++14
100 / 100
392 ms 53348 KB
# include <bits/stdc++.h>
# define ll long long
# define fi first
# define se second
using namespace std;

int main() {
	int N;
	ll A, B;
	scanf("%d %lld %lld", &N, &A, &B);
	
	ll P = A / __gcd(A, B + 1ll);
	vector< pair<ll, ll> > ln;
	ln.clear();
	
	ll BC = 0ll;
	
	bool cek = 1;
	if(1e18 / B >= P) BC = B * P;
	else cek = 0;
	
//	cout<<cek<<" "<<BC<<endl;
	
	ll ans = 0ll;
	for(int i=0;i<N;i++) {
		ll L, R;
		scanf("%lld %lld", &L, &R);
		if(cek && (R - L + 1) >= BC) {
			printf("%lld\n", BC);
			return 0;
		}
		if(!cek) ans += R - L + 1ll;
		else {
			if(L%BC <= R%BC) {
				ln.push_back(make_pair(L%BC, R%BC));
			} else {
				ln.push_back(make_pair(L%BC, BC - 1));
				ln.push_back(make_pair(0, R%BC));
			}
		}
	}
	
	if(!cek) printf("%lld\n", ans);
	else {
		sort(ln.begin(), ln.end());
		ll nw = -1ll, as = 0ll;
		for(auto p : ln) {
		//	cout<<p.fi<<" "<<p.se<<endl;
			if(nw < p.fi) {
				as += p.se - p.fi + 1ll; 
			} else if(nw < p.se) {
				as += p.se - nw;
			}
			nw = max(nw, p.se);
		}
		printf("%lld\n", as);
		return 0;
	}
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  scanf("%d %lld %lld", &N, &A, &B);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   scanf("%lld %lld", &L, &R);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 4 ms 948 KB Output is correct
3 Correct 5 ms 980 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 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 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 4 ms 980 KB Output is correct
17 Correct 37 ms 5640 KB Output is correct
18 Correct 0 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 245 ms 41352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 367 ms 53244 KB Output is correct
3 Correct 380 ms 53312 KB Output is correct
4 Correct 330 ms 53264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 367 ms 53244 KB Output is correct
3 Correct 380 ms 53312 KB Output is correct
4 Correct 330 ms 53264 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 330 ms 53188 KB Output is correct
7 Correct 339 ms 53168 KB Output is correct
8 Correct 330 ms 53156 KB Output is correct
9 Correct 357 ms 53240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 367 ms 53244 KB Output is correct
3 Correct 380 ms 53312 KB Output is correct
4 Correct 330 ms 53264 KB Output is correct
5 Correct 0 ms 304 KB Output is correct
6 Correct 34 ms 5636 KB Output is correct
7 Correct 35 ms 5592 KB Output is correct
8 Correct 32 ms 5652 KB Output is correct
9 Correct 33 ms 5584 KB Output is correct
10 Correct 34 ms 5652 KB Output is correct
11 Correct 34 ms 5688 KB Output is correct
12 Correct 32 ms 5704 KB Output is correct
13 Correct 35 ms 5620 KB Output is correct
14 Correct 32 ms 5676 KB Output is correct
15 Correct 37 ms 5596 KB Output is correct
16 Correct 35 ms 5692 KB Output is correct
17 Correct 33 ms 5576 KB Output is correct
18 Correct 340 ms 53268 KB Output is correct
19 Correct 326 ms 53216 KB Output is correct
20 Correct 354 ms 53268 KB Output is correct
21 Correct 35 ms 5700 KB Output is correct
22 Correct 31 ms 5636 KB Output is correct
23 Correct 104 ms 18452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 45 ms 5652 KB Output is correct
3 Correct 37 ms 5696 KB Output is correct
4 Correct 386 ms 53272 KB Output is correct
5 Correct 35 ms 5588 KB Output is correct
6 Correct 35 ms 5600 KB Output is correct
7 Correct 35 ms 5588 KB Output is correct
8 Correct 36 ms 5644 KB Output is correct
9 Correct 34 ms 5704 KB Output is correct
10 Correct 34 ms 5688 KB Output is correct
11 Correct 43 ms 5692 KB Output is correct
12 Correct 31 ms 5692 KB Output is correct
13 Correct 46 ms 5632 KB Output is correct
14 Correct 360 ms 53204 KB Output is correct
15 Correct 40 ms 5724 KB Output is correct
16 Correct 331 ms 53200 KB Output is correct
17 Correct 334 ms 53336 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 4 ms 948 KB Output is correct
3 Correct 5 ms 980 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 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 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 4 ms 980 KB Output is correct
17 Correct 37 ms 5640 KB Output is correct
18 Correct 0 ms 296 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 300 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 352 KB Output is correct
27 Correct 1 ms 312 KB Output is correct
28 Correct 245 ms 41352 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 367 ms 53244 KB Output is correct
31 Correct 380 ms 53312 KB Output is correct
32 Correct 330 ms 53264 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 330 ms 53188 KB Output is correct
35 Correct 339 ms 53168 KB Output is correct
36 Correct 330 ms 53156 KB Output is correct
37 Correct 357 ms 53240 KB Output is correct
38 Correct 0 ms 304 KB Output is correct
39 Correct 34 ms 5636 KB Output is correct
40 Correct 35 ms 5592 KB Output is correct
41 Correct 32 ms 5652 KB Output is correct
42 Correct 33 ms 5584 KB Output is correct
43 Correct 34 ms 5652 KB Output is correct
44 Correct 34 ms 5688 KB Output is correct
45 Correct 32 ms 5704 KB Output is correct
46 Correct 35 ms 5620 KB Output is correct
47 Correct 32 ms 5676 KB Output is correct
48 Correct 37 ms 5596 KB Output is correct
49 Correct 35 ms 5692 KB Output is correct
50 Correct 33 ms 5576 KB Output is correct
51 Correct 340 ms 53268 KB Output is correct
52 Correct 326 ms 53216 KB Output is correct
53 Correct 354 ms 53268 KB Output is correct
54 Correct 35 ms 5700 KB Output is correct
55 Correct 31 ms 5636 KB Output is correct
56 Correct 104 ms 18452 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 45 ms 5652 KB Output is correct
59 Correct 37 ms 5696 KB Output is correct
60 Correct 386 ms 53272 KB Output is correct
61 Correct 35 ms 5588 KB Output is correct
62 Correct 35 ms 5600 KB Output is correct
63 Correct 35 ms 5588 KB Output is correct
64 Correct 36 ms 5644 KB Output is correct
65 Correct 34 ms 5704 KB Output is correct
66 Correct 34 ms 5688 KB Output is correct
67 Correct 43 ms 5692 KB Output is correct
68 Correct 31 ms 5692 KB Output is correct
69 Correct 46 ms 5632 KB Output is correct
70 Correct 360 ms 53204 KB Output is correct
71 Correct 40 ms 5724 KB Output is correct
72 Correct 331 ms 53200 KB Output is correct
73 Correct 334 ms 53336 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 300 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 3 ms 980 KB Output is correct
80 Correct 392 ms 53180 KB Output is correct
81 Correct 385 ms 53224 KB Output is correct
82 Correct 353 ms 53336 KB Output is correct
83 Correct 348 ms 53260 KB Output is correct
84 Correct 358 ms 53348 KB Output is correct
85 Correct 348 ms 53252 KB Output is correct
86 Correct 100 ms 18440 KB Output is correct
87 Correct 1 ms 212 KB Output is correct