답안 #983752

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
983752 2024-05-16T04:10:44 Z pcc 이상한 기계 (APIO19_strange_device) C++17
100 / 100
443 ms 70400 KB
#include <bits/stdc++.h>
using namespace std;

#define ll __int128_t
#define pll pair<ll,ll>
#define fs first
#define sc second
ll N,A,B;
ll cyc;
vector<pll> v;

ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	while(b){
		a %= b;
		swap(a,b);
	}
	return a;
}

ll get_cyc(){
	ll re = B;
	ll tmp = (B+1)%A;
	if(!tmp)return B;
	tmp = A/gcd(A,B+1);
	return tmp*B;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	long long buf;
	cin>>buf;N = buf;
	cin>>buf;A = buf;
	cin>>buf;B = buf;
	cyc = get_cyc();
	for(int i = 0;i<N;i++){
		long long l,r;
		cin>>l>>r;
		if(r-l+1>=cyc)v.push_back(pll(0,cyc-1));
		else{
			if(l%cyc>r%cyc){
				v.push_back(pll(l%cyc,cyc-1));
				v.push_back(pll(0,r%cyc));
			}
			else{
				v.push_back(pll(l%cyc,r%cyc));
			}
		}
	}
	sort(v.begin(),v.end());
	long long ans = 0;
	ll rp = 0;
	for(auto &i:v){
		if(rp<i.fs){
			ans += i.sc-i.fs+1;
			rp = i.sc+1;
		}
		else{
			ans += max((ll)0,i.sc-rp+1);
			rp = max(rp,i.sc+1);
		}
	}
	cout<<ans<<'\n';
	return 0;
}

Compilation message

strange_device.cpp: In function '__int128 get_cyc()':
strange_device.cpp:22:5: warning: unused variable 're' [-Wunused-variable]
   22 |  ll re = B;
      |     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 992 KB Output is correct
3 Correct 4 ms 992 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 988 KB Output is correct
17 Correct 38 ms 4888 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 257 ms 56836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 337 ms 34416 KB Output is correct
3 Correct 329 ms 33448 KB Output is correct
4 Correct 323 ms 34152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 337 ms 34416 KB Output is correct
3 Correct 329 ms 33448 KB Output is correct
4 Correct 323 ms 34152 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 346 ms 33444 KB Output is correct
7 Correct 325 ms 68824 KB Output is correct
8 Correct 329 ms 69508 KB Output is correct
9 Correct 385 ms 69284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 337 ms 34416 KB Output is correct
3 Correct 329 ms 33448 KB Output is correct
4 Correct 323 ms 34152 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 31 ms 5472 KB Output is correct
7 Correct 39 ms 7380 KB Output is correct
8 Correct 32 ms 7880 KB Output is correct
9 Correct 33 ms 7880 KB Output is correct
10 Correct 32 ms 8912 KB Output is correct
11 Correct 41 ms 8976 KB Output is correct
12 Correct 32 ms 8404 KB Output is correct
13 Correct 35 ms 7376 KB Output is correct
14 Correct 31 ms 7884 KB Output is correct
15 Correct 37 ms 9052 KB Output is correct
16 Correct 36 ms 8148 KB Output is correct
17 Correct 34 ms 8656 KB Output is correct
18 Correct 345 ms 68792 KB Output is correct
19 Correct 327 ms 69804 KB Output is correct
20 Correct 416 ms 69860 KB Output is correct
21 Correct 36 ms 7368 KB Output is correct
22 Correct 31 ms 7368 KB Output is correct
23 Correct 108 ms 27896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 35 ms 4820 KB Output is correct
3 Correct 37 ms 9172 KB Output is correct
4 Correct 443 ms 70228 KB Output is correct
5 Correct 37 ms 7236 KB Output is correct
6 Correct 36 ms 7664 KB Output is correct
7 Correct 36 ms 7712 KB Output is correct
8 Correct 39 ms 8916 KB Output is correct
9 Correct 40 ms 9160 KB Output is correct
10 Correct 37 ms 9096 KB Output is correct
11 Correct 35 ms 7632 KB Output is correct
12 Correct 31 ms 8140 KB Output is correct
13 Correct 35 ms 8660 KB Output is correct
14 Correct 404 ms 69796 KB Output is correct
15 Correct 37 ms 8392 KB Output is correct
16 Correct 329 ms 70400 KB Output is correct
17 Correct 335 ms 69344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 992 KB Output is correct
3 Correct 4 ms 992 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 988 KB Output is correct
17 Correct 38 ms 4888 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 257 ms 56836 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 337 ms 34416 KB Output is correct
31 Correct 329 ms 33448 KB Output is correct
32 Correct 323 ms 34152 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 346 ms 33444 KB Output is correct
35 Correct 325 ms 68824 KB Output is correct
36 Correct 329 ms 69508 KB Output is correct
37 Correct 385 ms 69284 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 31 ms 5472 KB Output is correct
40 Correct 39 ms 7380 KB Output is correct
41 Correct 32 ms 7880 KB Output is correct
42 Correct 33 ms 7880 KB Output is correct
43 Correct 32 ms 8912 KB Output is correct
44 Correct 41 ms 8976 KB Output is correct
45 Correct 32 ms 8404 KB Output is correct
46 Correct 35 ms 7376 KB Output is correct
47 Correct 31 ms 7884 KB Output is correct
48 Correct 37 ms 9052 KB Output is correct
49 Correct 36 ms 8148 KB Output is correct
50 Correct 34 ms 8656 KB Output is correct
51 Correct 345 ms 68792 KB Output is correct
52 Correct 327 ms 69804 KB Output is correct
53 Correct 416 ms 69860 KB Output is correct
54 Correct 36 ms 7368 KB Output is correct
55 Correct 31 ms 7368 KB Output is correct
56 Correct 108 ms 27896 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 35 ms 4820 KB Output is correct
59 Correct 37 ms 9172 KB Output is correct
60 Correct 443 ms 70228 KB Output is correct
61 Correct 37 ms 7236 KB Output is correct
62 Correct 36 ms 7664 KB Output is correct
63 Correct 36 ms 7712 KB Output is correct
64 Correct 39 ms 8916 KB Output is correct
65 Correct 40 ms 9160 KB Output is correct
66 Correct 37 ms 9096 KB Output is correct
67 Correct 35 ms 7632 KB Output is correct
68 Correct 31 ms 8140 KB Output is correct
69 Correct 35 ms 8660 KB Output is correct
70 Correct 404 ms 69796 KB Output is correct
71 Correct 37 ms 8392 KB Output is correct
72 Correct 329 ms 70400 KB Output is correct
73 Correct 335 ms 69344 KB Output is correct
74 Correct 1 ms 348 KB Output is correct
75 Correct 1 ms 348 KB Output is correct
76 Correct 0 ms 456 KB Output is correct
77 Correct 0 ms 452 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 5 ms 1364 KB Output is correct
80 Correct 442 ms 69164 KB Output is correct
81 Correct 441 ms 69548 KB Output is correct
82 Correct 400 ms 68988 KB Output is correct
83 Correct 394 ms 68776 KB Output is correct
84 Correct 396 ms 68836 KB Output is correct
85 Correct 385 ms 69392 KB Output is correct
86 Correct 108 ms 26804 KB Output is correct
87 Correct 0 ms 344 KB Output is correct