답안 #205867

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
205867 2020-03-01T09:15:01 Z mraron 이상한 기계 (APIO19_strange_device) C++14
100 / 100
2340 ms 67188 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	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 7 ms 256 KB Output is correct
2 Correct 27 ms 1272 KB Output is correct
3 Correct 28 ms 1272 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 428 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 5 ms 248 KB Output is correct
9 Correct 5 ms 380 KB Output is correct
10 Correct 6 ms 256 KB Output is correct
11 Correct 6 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 26 ms 1272 KB Output is correct
17 Correct 234 ms 7916 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 7 ms 376 KB Output is correct
3 Correct 8 ms 376 KB Output is correct
4 Correct 7 ms 376 KB Output is correct
5 Correct 1576 ms 55800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 376 KB Output is correct
2 Correct 2213 ms 46280 KB Output is correct
3 Correct 2179 ms 46228 KB Output is correct
4 Correct 2209 ms 67184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 376 KB Output is correct
2 Correct 2213 ms 46280 KB Output is correct
3 Correct 2179 ms 46228 KB Output is correct
4 Correct 2209 ms 67184 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 2205 ms 67188 KB Output is correct
7 Correct 2221 ms 66124 KB Output is correct
8 Correct 2224 ms 67156 KB Output is correct
9 Correct 2315 ms 65920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 376 KB Output is correct
2 Correct 2213 ms 46280 KB Output is correct
3 Correct 2179 ms 46228 KB Output is correct
4 Correct 2209 ms 67184 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 222 ms 7788 KB Output is correct
7 Correct 237 ms 7920 KB Output is correct
8 Correct 234 ms 7788 KB Output is correct
9 Correct 238 ms 7916 KB Output is correct
10 Correct 232 ms 7788 KB Output is correct
11 Correct 235 ms 7788 KB Output is correct
12 Correct 231 ms 7788 KB Output is correct
13 Correct 229 ms 7932 KB Output is correct
14 Correct 243 ms 7788 KB Output is correct
15 Correct 233 ms 7788 KB Output is correct
16 Correct 242 ms 7788 KB Output is correct
17 Correct 229 ms 7788 KB Output is correct
18 Correct 2317 ms 66748 KB Output is correct
19 Correct 2264 ms 66072 KB Output is correct
20 Correct 2321 ms 66772 KB Output is correct
21 Correct 231 ms 7916 KB Output is correct
22 Correct 228 ms 8060 KB Output is correct
23 Correct 732 ms 27120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 228 ms 7788 KB Output is correct
3 Correct 231 ms 7908 KB Output is correct
4 Correct 2292 ms 66840 KB Output is correct
5 Correct 228 ms 7788 KB Output is correct
6 Correct 227 ms 7788 KB Output is correct
7 Correct 228 ms 7916 KB Output is correct
8 Correct 226 ms 7916 KB Output is correct
9 Correct 233 ms 7812 KB Output is correct
10 Correct 230 ms 7916 KB Output is correct
11 Correct 237 ms 7788 KB Output is correct
12 Correct 226 ms 7788 KB Output is correct
13 Correct 227 ms 7788 KB Output is correct
14 Correct 2260 ms 66892 KB Output is correct
15 Correct 233 ms 7788 KB Output is correct
16 Correct 2218 ms 66880 KB Output is correct
17 Correct 2217 ms 67056 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 256 KB Output is correct
2 Correct 27 ms 1272 KB Output is correct
3 Correct 28 ms 1272 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 428 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 5 ms 248 KB Output is correct
9 Correct 5 ms 380 KB Output is correct
10 Correct 6 ms 256 KB Output is correct
11 Correct 6 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 26 ms 1272 KB Output is correct
17 Correct 234 ms 7916 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
19 Correct 5 ms 256 KB Output is correct
20 Correct 5 ms 256 KB Output is correct
21 Correct 5 ms 256 KB Output is correct
22 Correct 5 ms 256 KB Output is correct
23 Correct 5 ms 256 KB Output is correct
24 Correct 5 ms 256 KB Output is correct
25 Correct 7 ms 376 KB Output is correct
26 Correct 8 ms 376 KB Output is correct
27 Correct 7 ms 376 KB Output is correct
28 Correct 1576 ms 55800 KB Output is correct
29 Correct 7 ms 376 KB Output is correct
30 Correct 2213 ms 46280 KB Output is correct
31 Correct 2179 ms 46228 KB Output is correct
32 Correct 2209 ms 67184 KB Output is correct
33 Correct 5 ms 256 KB Output is correct
34 Correct 2205 ms 67188 KB Output is correct
35 Correct 2221 ms 66124 KB Output is correct
36 Correct 2224 ms 67156 KB Output is correct
37 Correct 2315 ms 65920 KB Output is correct
38 Correct 5 ms 256 KB Output is correct
39 Correct 222 ms 7788 KB Output is correct
40 Correct 237 ms 7920 KB Output is correct
41 Correct 234 ms 7788 KB Output is correct
42 Correct 238 ms 7916 KB Output is correct
43 Correct 232 ms 7788 KB Output is correct
44 Correct 235 ms 7788 KB Output is correct
45 Correct 231 ms 7788 KB Output is correct
46 Correct 229 ms 7932 KB Output is correct
47 Correct 243 ms 7788 KB Output is correct
48 Correct 233 ms 7788 KB Output is correct
49 Correct 242 ms 7788 KB Output is correct
50 Correct 229 ms 7788 KB Output is correct
51 Correct 2317 ms 66748 KB Output is correct
52 Correct 2264 ms 66072 KB Output is correct
53 Correct 2321 ms 66772 KB Output is correct
54 Correct 231 ms 7916 KB Output is correct
55 Correct 228 ms 8060 KB Output is correct
56 Correct 732 ms 27120 KB Output is correct
57 Correct 5 ms 256 KB Output is correct
58 Correct 228 ms 7788 KB Output is correct
59 Correct 231 ms 7908 KB Output is correct
60 Correct 2292 ms 66840 KB Output is correct
61 Correct 228 ms 7788 KB Output is correct
62 Correct 227 ms 7788 KB Output is correct
63 Correct 228 ms 7916 KB Output is correct
64 Correct 226 ms 7916 KB Output is correct
65 Correct 233 ms 7812 KB Output is correct
66 Correct 230 ms 7916 KB Output is correct
67 Correct 237 ms 7788 KB Output is correct
68 Correct 226 ms 7788 KB Output is correct
69 Correct 227 ms 7788 KB Output is correct
70 Correct 2260 ms 66892 KB Output is correct
71 Correct 233 ms 7788 KB Output is correct
72 Correct 2218 ms 66880 KB Output is correct
73 Correct 2217 ms 67056 KB Output is correct
74 Correct 5 ms 256 KB Output is correct
75 Correct 6 ms 504 KB Output is correct
76 Correct 5 ms 256 KB Output is correct
77 Correct 5 ms 256 KB Output is correct
78 Correct 5 ms 256 KB Output is correct
79 Correct 28 ms 1272 KB Output is correct
80 Correct 2340 ms 67116 KB Output is correct
81 Correct 2293 ms 66976 KB Output is correct
82 Correct 2257 ms 66880 KB Output is correct
83 Correct 2264 ms 66924 KB Output is correct
84 Correct 2268 ms 66652 KB Output is correct
85 Correct 2238 ms 66216 KB Output is correct
86 Correct 746 ms 26720 KB Output is correct
87 Correct 5 ms 256 KB Output is correct