Submission #638417

# Submission time Handle Problem Language Result Execution time Memory
638417 2022-09-05T21:35:42 Z LeticiaFCS Wish (LMIO19_noras) C++17
100 / 100
165 ms 14888 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 = 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?)
*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 320 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 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 1 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 0 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 340 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 320 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 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 1 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 0 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 340 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 47 ms 7360 KB Output is correct
24 Correct 49 ms 7404 KB Output is correct
25 Correct 60 ms 7448 KB Output is correct
26 Correct 63 ms 7472 KB Output is correct
27 Correct 42 ms 4144 KB Output is correct
28 Correct 45 ms 6788 KB Output is correct
29 Correct 48 ms 6780 KB Output is correct
30 Correct 45 ms 6836 KB Output is correct
31 Correct 48 ms 6820 KB Output is correct
32 Correct 69 ms 7432 KB Output is correct
33 Correct 67 ms 7408 KB Output is correct
34 Correct 77 ms 7468 KB Output is correct
35 Correct 73 ms 7372 KB Output is correct
36 Correct 65 ms 7352 KB Output is correct
37 Correct 53 ms 5176 KB Output is correct
38 Correct 43 ms 5160 KB Output is correct
39 Correct 41 ms 4228 KB Output is correct
40 Correct 41 ms 4508 KB Output is correct
41 Correct 42 ms 4152 KB Output is correct
42 Correct 40 ms 4152 KB Output is correct
43 Correct 151 ms 14740 KB Output is correct
44 Correct 165 ms 14888 KB Output is correct
45 Correct 150 ms 14876 KB Output is correct
46 Correct 151 ms 14872 KB Output is correct
47 Correct 157 ms 14864 KB Output is correct
48 Correct 134 ms 14204 KB Output is correct
49 Correct 131 ms 14260 KB Output is correct
50 Correct 133 ms 14168 KB Output is correct
51 Correct 131 ms 14248 KB Output is correct
52 Correct 136 ms 14264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 320 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 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 1 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 0 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 340 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 328 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 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 320 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 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 1 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 0 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 340 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 47 ms 7360 KB Output is correct
24 Correct 49 ms 7404 KB Output is correct
25 Correct 60 ms 7448 KB Output is correct
26 Correct 63 ms 7472 KB Output is correct
27 Correct 42 ms 4144 KB Output is correct
28 Correct 45 ms 6788 KB Output is correct
29 Correct 48 ms 6780 KB Output is correct
30 Correct 45 ms 6836 KB Output is correct
31 Correct 48 ms 6820 KB Output is correct
32 Correct 69 ms 7432 KB Output is correct
33 Correct 67 ms 7408 KB Output is correct
34 Correct 77 ms 7468 KB Output is correct
35 Correct 73 ms 7372 KB Output is correct
36 Correct 65 ms 7352 KB Output is correct
37 Correct 53 ms 5176 KB Output is correct
38 Correct 43 ms 5160 KB Output is correct
39 Correct 41 ms 4228 KB Output is correct
40 Correct 41 ms 4508 KB Output is correct
41 Correct 42 ms 4152 KB Output is correct
42 Correct 40 ms 4152 KB Output is correct
43 Correct 151 ms 14740 KB Output is correct
44 Correct 165 ms 14888 KB Output is correct
45 Correct 150 ms 14876 KB Output is correct
46 Correct 151 ms 14872 KB Output is correct
47 Correct 157 ms 14864 KB Output is correct
48 Correct 134 ms 14204 KB Output is correct
49 Correct 131 ms 14260 KB Output is correct
50 Correct 133 ms 14168 KB Output is correct
51 Correct 131 ms 14248 KB Output is correct
52 Correct 136 ms 14264 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 336 KB Output is correct
57 Correct 1 ms 332 KB Output is correct
58 Correct 1 ms 328 KB Output is correct
59 Correct 47 ms 7468 KB Output is correct
60 Correct 50 ms 3924 KB Output is correct
61 Correct 52 ms 4196 KB Output is correct
62 Correct 45 ms 4540 KB Output is correct
63 Correct 55 ms 3964 KB Output is correct
64 Correct 54 ms 3816 KB Output is correct
65 Correct 61 ms 3940 KB Output is correct
66 Correct 69 ms 3972 KB Output is correct
67 Correct 53 ms 3772 KB Output is correct
68 Correct 73 ms 7484 KB Output is correct
69 Correct 69 ms 7360 KB Output is correct
70 Correct 80 ms 7468 KB Output is correct
71 Correct 72 ms 7440 KB Output is correct
72 Correct 67 ms 7472 KB Output is correct
73 Correct 41 ms 4904 KB Output is correct
74 Correct 44 ms 6844 KB Output is correct
75 Correct 52 ms 6852 KB Output is correct
76 Correct 43 ms 4412 KB Output is correct
77 Correct 142 ms 13260 KB Output is correct
78 Correct 149 ms 13272 KB Output is correct
79 Correct 149 ms 13328 KB Output is correct
80 Correct 151 ms 13340 KB Output is correct
81 Correct 146 ms 13320 KB Output is correct
82 Correct 143 ms 14220 KB Output is correct
83 Correct 135 ms 14268 KB Output is correct
84 Correct 147 ms 14116 KB Output is correct
85 Correct 135 ms 14100 KB Output is correct
86 Correct 135 ms 14240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 320 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 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 1 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 0 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 340 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 47 ms 7360 KB Output is correct
24 Correct 49 ms 7404 KB Output is correct
25 Correct 60 ms 7448 KB Output is correct
26 Correct 63 ms 7472 KB Output is correct
27 Correct 42 ms 4144 KB Output is correct
28 Correct 45 ms 6788 KB Output is correct
29 Correct 48 ms 6780 KB Output is correct
30 Correct 45 ms 6836 KB Output is correct
31 Correct 48 ms 6820 KB Output is correct
32 Correct 69 ms 7432 KB Output is correct
33 Correct 67 ms 7408 KB Output is correct
34 Correct 77 ms 7468 KB Output is correct
35 Correct 73 ms 7372 KB Output is correct
36 Correct 65 ms 7352 KB Output is correct
37 Correct 53 ms 5176 KB Output is correct
38 Correct 43 ms 5160 KB Output is correct
39 Correct 41 ms 4228 KB Output is correct
40 Correct 41 ms 4508 KB Output is correct
41 Correct 42 ms 4152 KB Output is correct
42 Correct 40 ms 4152 KB Output is correct
43 Correct 151 ms 14740 KB Output is correct
44 Correct 165 ms 14888 KB Output is correct
45 Correct 150 ms 14876 KB Output is correct
46 Correct 151 ms 14872 KB Output is correct
47 Correct 157 ms 14864 KB Output is correct
48 Correct 134 ms 14204 KB Output is correct
49 Correct 131 ms 14260 KB Output is correct
50 Correct 133 ms 14168 KB Output is correct
51 Correct 131 ms 14248 KB Output is correct
52 Correct 136 ms 14264 KB Output is correct
53 Correct 47 ms 7468 KB Output is correct
54 Correct 50 ms 3924 KB Output is correct
55 Correct 52 ms 4196 KB Output is correct
56 Correct 45 ms 4540 KB Output is correct
57 Correct 55 ms 3964 KB Output is correct
58 Correct 54 ms 3816 KB Output is correct
59 Correct 61 ms 3940 KB Output is correct
60 Correct 69 ms 3972 KB Output is correct
61 Correct 53 ms 3772 KB Output is correct
62 Correct 73 ms 7484 KB Output is correct
63 Correct 69 ms 7360 KB Output is correct
64 Correct 80 ms 7468 KB Output is correct
65 Correct 72 ms 7440 KB Output is correct
66 Correct 67 ms 7472 KB Output is correct
67 Correct 41 ms 4904 KB Output is correct
68 Correct 44 ms 6844 KB Output is correct
69 Correct 52 ms 6852 KB Output is correct
70 Correct 43 ms 4412 KB Output is correct
71 Correct 142 ms 13260 KB Output is correct
72 Correct 149 ms 13272 KB Output is correct
73 Correct 149 ms 13328 KB Output is correct
74 Correct 151 ms 13340 KB Output is correct
75 Correct 146 ms 13320 KB Output is correct
76 Correct 143 ms 14220 KB Output is correct
77 Correct 135 ms 14268 KB Output is correct
78 Correct 147 ms 14116 KB Output is correct
79 Correct 135 ms 14100 KB Output is correct
80 Correct 135 ms 14240 KB Output is correct
81 Correct 1 ms 212 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 336 KB Output is correct
85 Correct 1 ms 332 KB Output is correct
86 Correct 1 ms 328 KB Output is correct
87 Correct 72 ms 4060 KB Output is correct
88 Correct 70 ms 4076 KB Output is correct
89 Correct 67 ms 3860 KB Output is correct
90 Correct 66 ms 3912 KB Output is correct
91 Correct 71 ms 4000 KB Output is correct
92 Correct 74 ms 3996 KB Output is correct
93 Correct 69 ms 3948 KB Output is correct
94 Correct 67 ms 4196 KB Output is correct
95 Correct 77 ms 3984 KB Output is correct
96 Correct 66 ms 4008 KB Output is correct
97 Correct 54 ms 7288 KB Output is correct
98 Correct 60 ms 7320 KB Output is correct
99 Correct 52 ms 7244 KB Output is correct
100 Correct 52 ms 7260 KB Output is correct
101 Correct 50 ms 7340 KB Output is correct
102 Correct 57 ms 7348 KB Output is correct
103 Correct 54 ms 7288 KB Output is correct
104 Correct 56 ms 7236 KB Output is correct
105 Correct 52 ms 7344 KB Output is correct
106 Correct 56 ms 7296 KB Output is correct