답안 #379172

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
379172 2021-03-17T12:30:09 Z Bill_00 이상한 기계 (APIO19_strange_device) C++14
100 / 100
1755 ms 69320 KB
#include <bits/stdc++.h>
typedef long long ll;
#define N 20005
#define ff first
#define ss second
#define pb push_back
using namespace std;
ll gcd(ll a,ll b){
	while(a!=0 && b!=0){
		if(a>b){
			a=a%b;
		}
		else b=b%a;
	}
	return max(a,b);
}
vector<pair<pair<ll,ll>,pair<ll,ll> > >v;
int main(){
	ll n,a,b;
	cin >> n >> a >> b;
	ll k=gcd(a,(b+1));
	k=a/k;
	ll y=1e18;
	for(int i=1;i<=n;i++){
		ll l,r;
		cin >> l >> r;
		if(y/b>=k){
			if(k*b<=(r-l+1)){
				cout << k*b;
				return 0;
			}
		}
		ll x1=(l/b)%k;
		ll y1=l%b;
		ll x2=(r/b)%k;
		ll y2=r%b;
		// cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << '\n';
		if((x1==x2 && y2<y1) || x2<x1){
			v.pb({{0,0},{x2,y2}});
			v.pb({{x1,y1},{k-1,b-1}});
		}
		else v.pb({{x1,y1},{x2,y2}});
	}
	sort(v.begin(),v.end());
	ll ans=0;
	pair<ll,ll>e={-1,-1};
	for(int i=0;i<v.size();i++){
		ll x1=v[i].ff.ff;
		ll y1=v[i].ff.ss;
		ll x2=v[i].ss.ff;
		ll y2=v[i].ss.ss;
		if(e.ff>x2 || (e.ff==x2 && e.ss>=y2)){
			continue;
		}
		if(x1>e.ff || (x1==e.ff && y1>e.ss)){
			ans+=((x2-x1)*b+y2-y1+1);
			e={x2,y2};
			continue;
		}
		ans+=((x2-e.ff)*b+y2-e.ss);
		e={x2,y2};
	}
	cout << ans;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:47:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |  for(int i=0;i<v.size();i++){
      |              ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 18 ms 1384 KB Output is correct
3 Correct 20 ms 1384 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 512 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 17 ms 1384 KB Output is correct
17 Correct 164 ms 7260 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 236 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 524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 1151 ms 35060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1579 ms 36576 KB Output is correct
3 Correct 1566 ms 36584 KB Output is correct
4 Correct 1599 ms 69128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1579 ms 36576 KB Output is correct
3 Correct 1566 ms 36584 KB Output is correct
4 Correct 1599 ms 69128 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1635 ms 69208 KB Output is correct
7 Correct 1648 ms 69144 KB Output is correct
8 Correct 1592 ms 69008 KB Output is correct
9 Correct 1694 ms 69320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1579 ms 36576 KB Output is correct
3 Correct 1566 ms 36584 KB Output is correct
4 Correct 1599 ms 69128 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 157 ms 7260 KB Output is correct
7 Correct 162 ms 7260 KB Output is correct
8 Correct 158 ms 7260 KB Output is correct
9 Correct 166 ms 7380 KB Output is correct
10 Correct 167 ms 7408 KB Output is correct
11 Correct 161 ms 7260 KB Output is correct
12 Correct 163 ms 7424 KB Output is correct
13 Correct 163 ms 7308 KB Output is correct
14 Correct 158 ms 7636 KB Output is correct
15 Correct 164 ms 7436 KB Output is correct
16 Correct 163 ms 7260 KB Output is correct
17 Correct 158 ms 7260 KB Output is correct
18 Correct 1585 ms 68956 KB Output is correct
19 Correct 1562 ms 69008 KB Output is correct
20 Correct 1679 ms 69072 KB Output is correct
21 Correct 162 ms 7388 KB Output is correct
22 Correct 153 ms 7260 KB Output is correct
23 Correct 529 ms 26696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 162 ms 7260 KB Output is correct
3 Correct 171 ms 7260 KB Output is correct
4 Correct 1719 ms 36820 KB Output is correct
5 Correct 165 ms 7384 KB Output is correct
6 Correct 163 ms 7396 KB Output is correct
7 Correct 163 ms 7312 KB Output is correct
8 Correct 164 ms 7380 KB Output is correct
9 Correct 161 ms 7260 KB Output is correct
10 Correct 162 ms 7392 KB Output is correct
11 Correct 161 ms 7408 KB Output is correct
12 Correct 152 ms 7340 KB Output is correct
13 Correct 167 ms 7260 KB Output is correct
14 Correct 1671 ms 36588 KB Output is correct
15 Correct 166 ms 7260 KB Output is correct
16 Correct 1584 ms 69152 KB Output is correct
17 Correct 1580 ms 69040 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 18 ms 1384 KB Output is correct
3 Correct 20 ms 1384 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 512 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 17 ms 1384 KB Output is correct
17 Correct 164 ms 7260 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 236 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 524 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 3 ms 364 KB Output is correct
28 Correct 1151 ms 35060 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1579 ms 36576 KB Output is correct
31 Correct 1566 ms 36584 KB Output is correct
32 Correct 1599 ms 69128 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1635 ms 69208 KB Output is correct
35 Correct 1648 ms 69144 KB Output is correct
36 Correct 1592 ms 69008 KB Output is correct
37 Correct 1694 ms 69320 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 157 ms 7260 KB Output is correct
40 Correct 162 ms 7260 KB Output is correct
41 Correct 158 ms 7260 KB Output is correct
42 Correct 166 ms 7380 KB Output is correct
43 Correct 167 ms 7408 KB Output is correct
44 Correct 161 ms 7260 KB Output is correct
45 Correct 163 ms 7424 KB Output is correct
46 Correct 163 ms 7308 KB Output is correct
47 Correct 158 ms 7636 KB Output is correct
48 Correct 164 ms 7436 KB Output is correct
49 Correct 163 ms 7260 KB Output is correct
50 Correct 158 ms 7260 KB Output is correct
51 Correct 1585 ms 68956 KB Output is correct
52 Correct 1562 ms 69008 KB Output is correct
53 Correct 1679 ms 69072 KB Output is correct
54 Correct 162 ms 7388 KB Output is correct
55 Correct 153 ms 7260 KB Output is correct
56 Correct 529 ms 26696 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 162 ms 7260 KB Output is correct
59 Correct 171 ms 7260 KB Output is correct
60 Correct 1719 ms 36820 KB Output is correct
61 Correct 165 ms 7384 KB Output is correct
62 Correct 163 ms 7396 KB Output is correct
63 Correct 163 ms 7312 KB Output is correct
64 Correct 164 ms 7380 KB Output is correct
65 Correct 161 ms 7260 KB Output is correct
66 Correct 162 ms 7392 KB Output is correct
67 Correct 161 ms 7408 KB Output is correct
68 Correct 152 ms 7340 KB Output is correct
69 Correct 167 ms 7260 KB Output is correct
70 Correct 1671 ms 36588 KB Output is correct
71 Correct 166 ms 7260 KB Output is correct
72 Correct 1584 ms 69152 KB Output is correct
73 Correct 1580 ms 69040 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 16 ms 1384 KB Output is correct
80 Correct 1755 ms 69268 KB Output is correct
81 Correct 1725 ms 69120 KB Output is correct
82 Correct 1700 ms 69104 KB Output is correct
83 Correct 1678 ms 69056 KB Output is correct
84 Correct 1658 ms 69116 KB Output is correct
85 Correct 1699 ms 69032 KB Output is correct
86 Correct 535 ms 27056 KB Output is correct
87 Correct 1 ms 364 KB Output is correct