답안 #205869

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
205869 2020-03-01T09:16:36 Z mraron 이상한 기계 (APIO19_strange_device) C++14
100 / 100
660 ms 36060 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,a,b;
	cin>>n>>a>>b;
	ll len=0;
	vector<pair<ll,ll>> lst(n);
	for(int i=0;i<n;++i) {
		cin>>lst[i].first>>lst[i].second;
		len+=lst[i].second-lst[i].first+1;
	}
	ll div=__gcd(a,b+1);
	__int128 A=a/div;
	__int128 B=b;
	if(A*B>__int128(1000000000000000000LL)) {
		cout<<len<<"\n";
		return 0;
	}
	ll mod=(a/div)*b;
	vector<pair<ll,ll>> ivs;
	for(auto i:lst) {
		ll div1=i.first/mod, div2=i.second/mod;
		ll mod1=i.first%mod, mod2=i.second%mod;
		if(mod1<=mod2) {
			if(div1<div2) {
				cout<<mod<<"\n";
				return 0;
			}
			ivs.push_back({mod1,mod2});
		}else {
			if(div1+1==div2) {
				ivs.push_back({mod1, mod-1});
				ivs.push_back({0,mod2});
			}else {
				cout<<mod<<"\n";
				return 0;
			}
		}
	}
	sort(ivs.begin(), ivs.end());
	ll last=-1;
	ll ans=0;
	for(auto i:ivs) {
		if(last<i.second) {
			ans+=i.second-max(last+1, i.first)+1;
		}
		last=max(last, i.second);
	}
	cout<<ans<<"\n";
	
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 13 ms 1272 KB Output is correct
3 Correct 10 ms 1272 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 10 ms 1272 KB Output is correct
17 Correct 64 ms 7536 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 407 ms 34796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 554 ms 35928 KB Output is correct
3 Correct 553 ms 36060 KB Output is correct
4 Correct 518 ms 34648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 554 ms 35928 KB Output is correct
3 Correct 553 ms 36060 KB Output is correct
4 Correct 518 ms 34648 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 560 ms 34660 KB Output is correct
7 Correct 577 ms 34744 KB Output is correct
8 Correct 553 ms 34776 KB Output is correct
9 Correct 583 ms 34648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 554 ms 35928 KB Output is correct
3 Correct 553 ms 36060 KB Output is correct
4 Correct 518 ms 34648 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 62 ms 7536 KB Output is correct
7 Correct 61 ms 7536 KB Output is correct
8 Correct 57 ms 7536 KB Output is correct
9 Correct 58 ms 7536 KB Output is correct
10 Correct 63 ms 7536 KB Output is correct
11 Correct 63 ms 7532 KB Output is correct
12 Correct 58 ms 7536 KB Output is correct
13 Correct 63 ms 7536 KB Output is correct
14 Correct 58 ms 7536 KB Output is correct
15 Correct 66 ms 7536 KB Output is correct
16 Correct 64 ms 7536 KB Output is correct
17 Correct 59 ms 7664 KB Output is correct
18 Correct 547 ms 34776 KB Output is correct
19 Correct 546 ms 34648 KB Output is correct
20 Correct 613 ms 34772 KB Output is correct
21 Correct 67 ms 7540 KB Output is correct
22 Correct 56 ms 7664 KB Output is correct
23 Correct 174 ms 17380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 63 ms 7536 KB Output is correct
3 Correct 65 ms 7536 KB Output is correct
4 Correct 638 ms 34524 KB Output is correct
5 Correct 65 ms 7280 KB Output is correct
6 Correct 63 ms 7408 KB Output is correct
7 Correct 64 ms 7280 KB Output is correct
8 Correct 62 ms 7280 KB Output is correct
9 Correct 61 ms 7280 KB Output is correct
10 Correct 63 ms 7280 KB Output is correct
11 Correct 116 ms 7152 KB Output is correct
12 Correct 58 ms 7152 KB Output is correct
13 Correct 61 ms 7148 KB Output is correct
14 Correct 593 ms 34136 KB Output is correct
15 Correct 63 ms 6896 KB Output is correct
16 Correct 562 ms 33880 KB Output is correct
17 Correct 546 ms 33756 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 13 ms 1272 KB Output is correct
3 Correct 10 ms 1272 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 10 ms 1272 KB Output is correct
17 Correct 64 ms 7536 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 6 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 407 ms 34796 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 554 ms 35928 KB Output is correct
31 Correct 553 ms 36060 KB Output is correct
32 Correct 518 ms 34648 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 560 ms 34660 KB Output is correct
35 Correct 577 ms 34744 KB Output is correct
36 Correct 553 ms 34776 KB Output is correct
37 Correct 583 ms 34648 KB Output is correct
38 Correct 5 ms 376 KB Output is correct
39 Correct 62 ms 7536 KB Output is correct
40 Correct 61 ms 7536 KB Output is correct
41 Correct 57 ms 7536 KB Output is correct
42 Correct 58 ms 7536 KB Output is correct
43 Correct 63 ms 7536 KB Output is correct
44 Correct 63 ms 7532 KB Output is correct
45 Correct 58 ms 7536 KB Output is correct
46 Correct 63 ms 7536 KB Output is correct
47 Correct 58 ms 7536 KB Output is correct
48 Correct 66 ms 7536 KB Output is correct
49 Correct 64 ms 7536 KB Output is correct
50 Correct 59 ms 7664 KB Output is correct
51 Correct 547 ms 34776 KB Output is correct
52 Correct 546 ms 34648 KB Output is correct
53 Correct 613 ms 34772 KB Output is correct
54 Correct 67 ms 7540 KB Output is correct
55 Correct 56 ms 7664 KB Output is correct
56 Correct 174 ms 17380 KB Output is correct
57 Correct 5 ms 376 KB Output is correct
58 Correct 63 ms 7536 KB Output is correct
59 Correct 65 ms 7536 KB Output is correct
60 Correct 638 ms 34524 KB Output is correct
61 Correct 65 ms 7280 KB Output is correct
62 Correct 63 ms 7408 KB Output is correct
63 Correct 64 ms 7280 KB Output is correct
64 Correct 62 ms 7280 KB Output is correct
65 Correct 61 ms 7280 KB Output is correct
66 Correct 63 ms 7280 KB Output is correct
67 Correct 116 ms 7152 KB Output is correct
68 Correct 58 ms 7152 KB Output is correct
69 Correct 61 ms 7148 KB Output is correct
70 Correct 593 ms 34136 KB Output is correct
71 Correct 63 ms 6896 KB Output is correct
72 Correct 562 ms 33880 KB Output is correct
73 Correct 546 ms 33756 KB Output is correct
74 Correct 5 ms 376 KB Output is correct
75 Correct 5 ms 376 KB Output is correct
76 Correct 5 ms 376 KB Output is correct
77 Correct 5 ms 376 KB Output is correct
78 Correct 5 ms 376 KB Output is correct
79 Correct 11 ms 1272 KB Output is correct
80 Correct 646 ms 33624 KB Output is correct
81 Correct 619 ms 33496 KB Output is correct
82 Correct 568 ms 33240 KB Output is correct
83 Correct 588 ms 33156 KB Output is correct
84 Correct 585 ms 33112 KB Output is correct
85 Correct 660 ms 32984 KB Output is correct
86 Correct 169 ms 14436 KB Output is correct
87 Correct 5 ms 376 KB Output is correct