답안 #834079

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
834079 2023-08-22T10:37:35 Z Antekb 이상한 기계 (APIO19_strange_device) C++17
100 / 100
1267 ms 69040 KB
#include<bits/stdc++.h>
#define st first
#define nd second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define pp pop_back
#define mp make_pair
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vii = vector<pii>;
void debug(){cerr<<"\n";}
template<typename H, typename... T>
void debug(H h, T... t){
	cerr<<h;
	if(sizeof...(t)){
		cerr<<", ";
	}
	debug(t...);
}
#define deb(x...) cerr<<#x<<" = ";debug(x);

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

int main(){
	int n;
	ll a, b;
	cin>>n>>a>>b;
	if(b>=ll(1e18)/(a/gcd(a, b+1))){
		ll s=0;
		for(int i=0; i<n; i++){
			ll l, r;
			cin>>l>>r;
			s+=r-l+1;
		}
		cout<<s;
		return 0;
	}
	ll t=b*(a/__gcd(a, b+1));
	vector<pair<ll, int> > V;
	for(int i=0; i<n; i++){
		ll l, r;
		cin>>l>>r;
		if(r-l+1>=t){
			cout<<t;
			return 0;
		}
		l%=t;
		r%=t;
		if(l<=r){
			V.eb(l, 1);
			V.eb(r+1, -1);
		}
		else{
			V.eb(0, 1);
			V.eb(r+1, -1);
			V.eb(l, 1);
		}
	}
	V.eb(t, 0);
	sort(all(V));
	ll s=0, prv=0;
	int part=0;
	for(auto i:V){
		if(i.st!=prv){
			if(part>0)s+=i.st-prv;
			prv=i.st;
		}
		part+=i.nd;
	}
	cout<<s;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 11 ms 1104 KB Output is correct
3 Correct 11 ms 1104 KB Output is correct
4 Correct 0 ms 304 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 11 ms 1228 KB Output is correct
17 Correct 111 ms 4780 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 300 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 368 KB Output is correct
5 Correct 807 ms 56952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1084 ms 33380 KB Output is correct
3 Correct 1110 ms 69040 KB Output is correct
4 Correct 1079 ms 68824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1084 ms 33380 KB Output is correct
3 Correct 1110 ms 69040 KB Output is correct
4 Correct 1079 ms 68824 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1058 ms 69020 KB Output is correct
7 Correct 1048 ms 68864 KB Output is correct
8 Correct 1088 ms 69020 KB Output is correct
9 Correct 1170 ms 68880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1084 ms 33380 KB Output is correct
3 Correct 1110 ms 69040 KB Output is correct
4 Correct 1079 ms 68824 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 107 ms 7228 KB Output is correct
7 Correct 108 ms 7156 KB Output is correct
8 Correct 109 ms 7204 KB Output is correct
9 Correct 111 ms 7412 KB Output is correct
10 Correct 104 ms 7216 KB Output is correct
11 Correct 104 ms 7272 KB Output is correct
12 Correct 104 ms 7180 KB Output is correct
13 Correct 120 ms 7268 KB Output is correct
14 Correct 104 ms 7200 KB Output is correct
15 Correct 112 ms 7268 KB Output is correct
16 Correct 111 ms 7264 KB Output is correct
17 Correct 108 ms 7380 KB Output is correct
18 Correct 1062 ms 68972 KB Output is correct
19 Correct 1070 ms 68868 KB Output is correct
20 Correct 1178 ms 68960 KB Output is correct
21 Correct 119 ms 7272 KB Output is correct
22 Correct 104 ms 7264 KB Output is correct
23 Correct 334 ms 26640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 113 ms 4716 KB Output is correct
3 Correct 112 ms 7368 KB Output is correct
4 Correct 1208 ms 68888 KB Output is correct
5 Correct 109 ms 7252 KB Output is correct
6 Correct 110 ms 7260 KB Output is correct
7 Correct 109 ms 7236 KB Output is correct
8 Correct 111 ms 7188 KB Output is correct
9 Correct 109 ms 7208 KB Output is correct
10 Correct 148 ms 7244 KB Output is correct
11 Correct 113 ms 7272 KB Output is correct
12 Correct 104 ms 7264 KB Output is correct
13 Correct 111 ms 7216 KB Output is correct
14 Correct 1211 ms 68844 KB Output is correct
15 Correct 114 ms 7212 KB Output is correct
16 Correct 1161 ms 68892 KB Output is correct
17 Correct 1103 ms 68804 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 11 ms 1104 KB Output is correct
3 Correct 11 ms 1104 KB Output is correct
4 Correct 0 ms 304 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 11 ms 1228 KB Output is correct
17 Correct 111 ms 4780 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 300 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 368 KB Output is correct
28 Correct 807 ms 56952 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1084 ms 33380 KB Output is correct
31 Correct 1110 ms 69040 KB Output is correct
32 Correct 1079 ms 68824 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1058 ms 69020 KB Output is correct
35 Correct 1048 ms 68864 KB Output is correct
36 Correct 1088 ms 69020 KB Output is correct
37 Correct 1170 ms 68880 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 107 ms 7228 KB Output is correct
40 Correct 108 ms 7156 KB Output is correct
41 Correct 109 ms 7204 KB Output is correct
42 Correct 111 ms 7412 KB Output is correct
43 Correct 104 ms 7216 KB Output is correct
44 Correct 104 ms 7272 KB Output is correct
45 Correct 104 ms 7180 KB Output is correct
46 Correct 120 ms 7268 KB Output is correct
47 Correct 104 ms 7200 KB Output is correct
48 Correct 112 ms 7268 KB Output is correct
49 Correct 111 ms 7264 KB Output is correct
50 Correct 108 ms 7380 KB Output is correct
51 Correct 1062 ms 68972 KB Output is correct
52 Correct 1070 ms 68868 KB Output is correct
53 Correct 1178 ms 68960 KB Output is correct
54 Correct 119 ms 7272 KB Output is correct
55 Correct 104 ms 7264 KB Output is correct
56 Correct 334 ms 26640 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 113 ms 4716 KB Output is correct
59 Correct 112 ms 7368 KB Output is correct
60 Correct 1208 ms 68888 KB Output is correct
61 Correct 109 ms 7252 KB Output is correct
62 Correct 110 ms 7260 KB Output is correct
63 Correct 109 ms 7236 KB Output is correct
64 Correct 111 ms 7188 KB Output is correct
65 Correct 109 ms 7208 KB Output is correct
66 Correct 148 ms 7244 KB Output is correct
67 Correct 113 ms 7272 KB Output is correct
68 Correct 104 ms 7264 KB Output is correct
69 Correct 111 ms 7216 KB Output is correct
70 Correct 1211 ms 68844 KB Output is correct
71 Correct 114 ms 7212 KB Output is correct
72 Correct 1161 ms 68892 KB Output is correct
73 Correct 1103 ms 68804 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 300 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 14 ms 1260 KB Output is correct
80 Correct 1267 ms 68816 KB Output is correct
81 Correct 1252 ms 68924 KB Output is correct
82 Correct 1231 ms 68808 KB Output is correct
83 Correct 1193 ms 68856 KB Output is correct
84 Correct 1249 ms 68812 KB Output is correct
85 Correct 1206 ms 68908 KB Output is correct
86 Correct 348 ms 26676 KB Output is correct
87 Correct 1 ms 212 KB Output is correct