답안 #638416

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
638416 2022-09-05T21:32:14 Z LeticiaFCS Wish (LMIO19_noras) C++17
100 / 100
223 ms 17880 KB
#include "bits/stdc++.h"
#define st first
#define nd second
using lint = int64_t;
constexpr int MOD = int(1e9) + 7;
constexpr int INF = 0x3f3f3f3f;
constexpr int NINF = 0xcfcfcfcf;
constexpr lint LINF = 0x3f3f3f3f3f3f3f3f;
const long double PI = acosl(-1.0);
// Returns -1 if a < b, 0 if a = b and 1 if a > b.
int cmp_double(double a, double b = 0, double eps = 1e-9) {
	return a + eps > b ? b + eps > a ? 0 : 1 : -1;
}
using namespace std;


using ld = long double;



bool inCircle(ld x, ld y, ld dx, ld dy, ld r, ld t){
	return ( (x + dx*t)*(x + dx*t) + (y + dy*t)*(y + dy*t) ) <= r*r; 
}
pair<bool, lint> firstInCircle(ld x, ld y, ld dx, ld dy, ld r, ld dbt){	
	lint s = ld(dbt) - 2;
	lint e = s + 4;
	for(ld t = s; t<=e; t++)
		if(inCircle(x,y,dx,dy,r, t)) return {true,t};
	return {false, -1};
} 
pair<bool, lint> lastInCircle(ld x, ld y, ld dx, ld dy, ld r, ld dbt){	
	lint s = ld(dbt) + 2;
	lint e = s - 4;
	for(ld t = s; t>=e; t--)
		if(inCircle(x,y,dx,dy,r, t)) return {true,t};
	return {false, -1};
}


vector<lint> intersection(ld x, ld y, ld dx, ld dy, ld r){
	vector<lint> answer;
	
	ld a = (dx*dx + dy*dy);
	ld b = (2ll*x*dx + 2ll*y*dy);
	ld c = -(r*r - x*x - y*y);
	ld delta = b*b - 4ll*a*c;
	
	if(delta < 0) return answer;
	if(delta == 0){
		ld t = ld(-b) / ld(2*a);
		auto left = firstInCircle(x,y,dx,dy,r,t);
		if(!left.first) return {};
		auto right = lastInCircle(x,y,dx,dy,r,t);
		if(!right.first) return {};
		answer = {left.second, right.second};
	}else{
		auto left = firstInCircle(x,y,dx,dy,r, ( ld(-b) - sqrtl((ld)delta))/ ld(2*a) );
		if(!left.first) return {};
		auto right = lastInCircle(x,y,dx,dy,r, (ld(-b) + sqrtl((ld)delta))/ ld(2*a) );
		if(!right.first) return {};		
		answer = {left.second, right.second};
	}
	if(answer[0] < 0) answer[0] = 0;
	if(answer[0] > answer[1]) answer = {};
	else if(answer.back() < 0) answer = {};
	
	return answer;
}

vector<ld> comprTime;

int main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	comprTime = {-1};
	int n;
	lint r; cin>>n>>r;
	vector<vector<lint>> stars;
	for(int i=0; i<n; i++){
		lint x1, y1, x2, y2;
		cin>>x1>>y1>>x2>>y2;
		auto v = intersection(x1, y1, x2-x1, y2-y1, r);
		if(!v.empty()){
			stars.push_back(v);
			comprTime.push_back(v[0]);
			comprTime.push_back(v[1]);
		}
	}
	sort(comprTime.begin(), comprTime.end());
	comprTime.resize(distance(
		comprTime.begin(),
		unique(comprTime.begin(), comprTime.end())	
	));
	comprTime.push_back(comprTime.back()+1);
	
	vector<int> pref(comprTime.size());
	for(auto star : stars){
		int l = lower_bound(comprTime.begin(),comprTime.end(), star[0]) - comprTime.begin();
		int r = upper_bound(comprTime.begin(),comprTime.end(), star[1]) - comprTime.begin();
		pref[l]++;
		pref[r]--;
	}
	for(int i=1; i<int(comprTime.size()); i++)
		pref[i] += pref[i-1];
	cout<<*max_element(pref.begin(), pref.end())<<"\n";
	

	return 0;
}
/*
[  ]Leu o problema certo???
[  ]Ver se precisa de long long
[  ]Viu o limite dos fors (é n? é m?)
[  ]Tamanho do vetor, será que é 2e5 em vez de 1e5??
[  ]Testar sample
[  ]Testar casos de  borda
[  ]1LL no 1LL << i
[  ]Testar mod (é 1e9+7, mesmo?, será que o mod não ficou negativo?)
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 0 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 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 388 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 0 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 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 388 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 76 ms 8796 KB Output is correct
24 Correct 68 ms 8852 KB Output is correct
25 Correct 77 ms 8800 KB Output is correct
26 Correct 69 ms 8852 KB Output is correct
27 Correct 55 ms 4844 KB Output is correct
28 Correct 74 ms 8268 KB Output is correct
29 Correct 76 ms 8160 KB Output is correct
30 Correct 73 ms 8192 KB Output is correct
31 Correct 76 ms 8212 KB Output is correct
32 Correct 102 ms 8840 KB Output is correct
33 Correct 96 ms 8812 KB Output is correct
34 Correct 101 ms 8804 KB Output is correct
35 Correct 99 ms 8796 KB Output is correct
36 Correct 99 ms 8724 KB Output is correct
37 Correct 64 ms 6116 KB Output is correct
38 Correct 62 ms 6100 KB Output is correct
39 Correct 57 ms 4828 KB Output is correct
40 Correct 62 ms 5144 KB Output is correct
41 Correct 58 ms 4772 KB Output is correct
42 Correct 59 ms 4820 KB Output is correct
43 Correct 222 ms 17860 KB Output is correct
44 Correct 223 ms 17880 KB Output is correct
45 Correct 219 ms 17804 KB Output is correct
46 Correct 218 ms 17828 KB Output is correct
47 Correct 220 ms 17828 KB Output is correct
48 Correct 200 ms 17088 KB Output is correct
49 Correct 201 ms 17168 KB Output is correct
50 Correct 197 ms 17140 KB Output is correct
51 Correct 192 ms 17092 KB Output is correct
52 Correct 199 ms 17296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 0 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 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 388 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 340 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 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 0 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 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 388 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 76 ms 8796 KB Output is correct
24 Correct 68 ms 8852 KB Output is correct
25 Correct 77 ms 8800 KB Output is correct
26 Correct 69 ms 8852 KB Output is correct
27 Correct 55 ms 4844 KB Output is correct
28 Correct 74 ms 8268 KB Output is correct
29 Correct 76 ms 8160 KB Output is correct
30 Correct 73 ms 8192 KB Output is correct
31 Correct 76 ms 8212 KB Output is correct
32 Correct 102 ms 8840 KB Output is correct
33 Correct 96 ms 8812 KB Output is correct
34 Correct 101 ms 8804 KB Output is correct
35 Correct 99 ms 8796 KB Output is correct
36 Correct 99 ms 8724 KB Output is correct
37 Correct 64 ms 6116 KB Output is correct
38 Correct 62 ms 6100 KB Output is correct
39 Correct 57 ms 4828 KB Output is correct
40 Correct 62 ms 5144 KB Output is correct
41 Correct 58 ms 4772 KB Output is correct
42 Correct 59 ms 4820 KB Output is correct
43 Correct 222 ms 17860 KB Output is correct
44 Correct 223 ms 17880 KB Output is correct
45 Correct 219 ms 17804 KB Output is correct
46 Correct 218 ms 17828 KB Output is correct
47 Correct 220 ms 17828 KB Output is correct
48 Correct 200 ms 17088 KB Output is correct
49 Correct 201 ms 17168 KB Output is correct
50 Correct 197 ms 17140 KB Output is correct
51 Correct 192 ms 17092 KB Output is correct
52 Correct 199 ms 17296 KB Output is correct
53 Correct 1 ms 324 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 2 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 72 ms 8776 KB Output is correct
60 Correct 62 ms 4592 KB Output is correct
61 Correct 62 ms 4824 KB Output is correct
62 Correct 63 ms 5300 KB Output is correct
63 Correct 73 ms 4468 KB Output is correct
64 Correct 73 ms 4428 KB Output is correct
65 Correct 74 ms 4556 KB Output is correct
66 Correct 76 ms 4584 KB Output is correct
67 Correct 70 ms 4344 KB Output is correct
68 Correct 102 ms 8836 KB Output is correct
69 Correct 101 ms 8748 KB Output is correct
70 Correct 105 ms 8776 KB Output is correct
71 Correct 99 ms 8804 KB Output is correct
72 Correct 105 ms 8964 KB Output is correct
73 Correct 63 ms 5732 KB Output is correct
74 Correct 64 ms 8224 KB Output is correct
75 Correct 72 ms 8208 KB Output is correct
76 Correct 61 ms 5136 KB Output is correct
77 Correct 207 ms 16144 KB Output is correct
78 Correct 205 ms 15972 KB Output is correct
79 Correct 201 ms 15988 KB Output is correct
80 Correct 205 ms 15968 KB Output is correct
81 Correct 200 ms 15968 KB Output is correct
82 Correct 202 ms 17112 KB Output is correct
83 Correct 204 ms 17072 KB Output is correct
84 Correct 206 ms 17076 KB Output is correct
85 Correct 208 ms 17128 KB Output is correct
86 Correct 210 ms 17096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 0 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 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 388 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 76 ms 8796 KB Output is correct
24 Correct 68 ms 8852 KB Output is correct
25 Correct 77 ms 8800 KB Output is correct
26 Correct 69 ms 8852 KB Output is correct
27 Correct 55 ms 4844 KB Output is correct
28 Correct 74 ms 8268 KB Output is correct
29 Correct 76 ms 8160 KB Output is correct
30 Correct 73 ms 8192 KB Output is correct
31 Correct 76 ms 8212 KB Output is correct
32 Correct 102 ms 8840 KB Output is correct
33 Correct 96 ms 8812 KB Output is correct
34 Correct 101 ms 8804 KB Output is correct
35 Correct 99 ms 8796 KB Output is correct
36 Correct 99 ms 8724 KB Output is correct
37 Correct 64 ms 6116 KB Output is correct
38 Correct 62 ms 6100 KB Output is correct
39 Correct 57 ms 4828 KB Output is correct
40 Correct 62 ms 5144 KB Output is correct
41 Correct 58 ms 4772 KB Output is correct
42 Correct 59 ms 4820 KB Output is correct
43 Correct 222 ms 17860 KB Output is correct
44 Correct 223 ms 17880 KB Output is correct
45 Correct 219 ms 17804 KB Output is correct
46 Correct 218 ms 17828 KB Output is correct
47 Correct 220 ms 17828 KB Output is correct
48 Correct 200 ms 17088 KB Output is correct
49 Correct 201 ms 17168 KB Output is correct
50 Correct 197 ms 17140 KB Output is correct
51 Correct 192 ms 17092 KB Output is correct
52 Correct 199 ms 17296 KB Output is correct
53 Correct 72 ms 8776 KB Output is correct
54 Correct 62 ms 4592 KB Output is correct
55 Correct 62 ms 4824 KB Output is correct
56 Correct 63 ms 5300 KB Output is correct
57 Correct 73 ms 4468 KB Output is correct
58 Correct 73 ms 4428 KB Output is correct
59 Correct 74 ms 4556 KB Output is correct
60 Correct 76 ms 4584 KB Output is correct
61 Correct 70 ms 4344 KB Output is correct
62 Correct 102 ms 8836 KB Output is correct
63 Correct 101 ms 8748 KB Output is correct
64 Correct 105 ms 8776 KB Output is correct
65 Correct 99 ms 8804 KB Output is correct
66 Correct 105 ms 8964 KB Output is correct
67 Correct 63 ms 5732 KB Output is correct
68 Correct 64 ms 8224 KB Output is correct
69 Correct 72 ms 8208 KB Output is correct
70 Correct 61 ms 5136 KB Output is correct
71 Correct 207 ms 16144 KB Output is correct
72 Correct 205 ms 15972 KB Output is correct
73 Correct 201 ms 15988 KB Output is correct
74 Correct 205 ms 15968 KB Output is correct
75 Correct 200 ms 15968 KB Output is correct
76 Correct 202 ms 17112 KB Output is correct
77 Correct 204 ms 17072 KB Output is correct
78 Correct 206 ms 17076 KB Output is correct
79 Correct 208 ms 17128 KB Output is correct
80 Correct 210 ms 17096 KB Output is correct
81 Correct 1 ms 324 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 2 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 1 ms 340 KB Output is correct
86 Correct 1 ms 340 KB Output is correct
87 Correct 88 ms 4724 KB Output is correct
88 Correct 87 ms 8164 KB Output is correct
89 Correct 89 ms 7900 KB Output is correct
90 Correct 94 ms 7936 KB Output is correct
91 Correct 85 ms 8060 KB Output is correct
92 Correct 89 ms 7976 KB Output is correct
93 Correct 89 ms 8008 KB Output is correct
94 Correct 92 ms 8276 KB Output is correct
95 Correct 93 ms 7916 KB Output is correct
96 Correct 90 ms 8032 KB Output is correct
97 Correct 78 ms 11096 KB Output is correct
98 Correct 84 ms 10860 KB Output is correct
99 Correct 79 ms 10956 KB Output is correct
100 Correct 83 ms 10976 KB Output is correct
101 Correct 75 ms 10808 KB Output is correct
102 Correct 86 ms 10880 KB Output is correct
103 Correct 73 ms 10972 KB Output is correct
104 Correct 83 ms 10856 KB Output is correct
105 Correct 78 ms 10980 KB Output is correct
106 Correct 78 ms 10868 KB Output is correct