답안 #638402

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
638402 2022-09-05T20:48:31 Z LeticiaFCS Wish (LMIO19_noras) C++17
93 / 100
141 ms 18944 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;




vector<lint> intersection(lint x, lint y, lint dx, lint dy, lint r){
	vector<lint> answer;
	
	lint a = (dx*dx + dy*dy);
	lint b = (2*x*dx + 2*y*dy);
	lint c = -(r*r - x*x - y*y);
	lint delta = b*b - 4*a*c;
	
	if(delta < 0) return answer;
	if(delta == 0){
		ld t = ld(-b) / ld(2*a);
		answer = {ceil(t), floor(t)};
		return answer;
	}
	answer = {ceil( ( ld(-b) - sqrtl((ld)delta))/ ld(2*a) ),
		floor( (ld(-b) + sqrtl((ld)delta))/ ld(2*a) )
	};
	if(answer[0] > answer[1]) answer = {};
	if(answer.back() < 0) answer = {};
	else if(answer[0] < 0) answer[0] = 0;
	
	return answer;
}

vector<lint> comprTime;

int main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	comprTime = {-1};
	int n, r; cin>>n>>r;
	vector<vector<lint>> stars;
	for(int i=0; i<n; i++){
		int 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<lint> 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?)
*/

Compilation message

noras.cpp: In function 'std::vector<long int> intersection(lint, lint, lint, lint, lint)':
noras.cpp:33:17: warning: narrowing conversion of 'std::ceil(t)' from 'long double' to 'long int' [-Wnarrowing]
   33 |   answer = {ceil(t), floor(t)};
      |             ~~~~^~~
noras.cpp:33:17: warning: narrowing conversion of 'std::ceil(t)' from 'long double' to 'long int' [-Wnarrowing]
noras.cpp:33:27: warning: narrowing conversion of 'std::floor(t)' from 'long double' to 'long int' [-Wnarrowing]
   33 |   answer = {ceil(t), floor(t)};
      |                      ~~~~~^~~
noras.cpp:33:27: warning: narrowing conversion of 'std::floor(t)' from 'long double' to 'long int' [-Wnarrowing]
noras.cpp:36:16: warning: narrowing conversion of 'std::ceil((((ld)-(b) - sqrtl((ld)delta)) / (ld)(2 * a)))' from 'long double' to 'long int' [-Wnarrowing]
   36 |  answer = {ceil( ( ld(-b) - sqrtl((ld)delta))/ ld(2*a) ),
      |            ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
noras.cpp:36:16: warning: narrowing conversion of 'std::ceil((((ld)-(b) - sqrtl((ld)delta)) / (ld)(2 * a)))' from 'long double' to 'long int' [-Wnarrowing]
noras.cpp:37:8: warning: narrowing conversion of 'std::floor((((ld)-(b) + sqrtl((ld)delta)) / (ld)(2 * a)))' from 'long double' to 'long int' [-Wnarrowing]
   37 |   floor( (ld(-b) + sqrtl((ld)delta))/ ld(2*a) )
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
noras.cpp:37:8: warning: narrowing conversion of 'std::floor((((ld)-(b) + sqrtl((ld)delta)) / (ld)(2 * a)))' from 'long double' to 'long int' [-Wnarrowing]
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 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 368 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 336 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 324 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 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 332 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 0 ms 212 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 368 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 336 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 324 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 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 61 ms 8736 KB Output is correct
24 Correct 62 ms 8760 KB Output is correct
25 Correct 63 ms 8748 KB Output is correct
26 Correct 68 ms 8832 KB Output is correct
27 Correct 55 ms 6456 KB Output is correct
28 Correct 58 ms 8928 KB Output is correct
29 Correct 59 ms 9092 KB Output is correct
30 Correct 61 ms 8992 KB Output is correct
31 Correct 62 ms 9104 KB Output is correct
32 Correct 58 ms 8748 KB Output is correct
33 Correct 66 ms 8828 KB Output is correct
34 Correct 57 ms 8712 KB Output is correct
35 Correct 61 ms 8756 KB Output is correct
36 Correct 58 ms 8752 KB Output is correct
37 Correct 55 ms 8024 KB Output is correct
38 Correct 55 ms 7960 KB Output is correct
39 Correct 50 ms 8836 KB Output is correct
40 Correct 53 ms 8816 KB Output is correct
41 Correct 50 ms 8880 KB Output is correct
42 Correct 50 ms 9004 KB Output is correct
43 Correct 135 ms 18944 KB Output is correct
44 Correct 141 ms 18828 KB Output is correct
45 Correct 137 ms 18732 KB Output is correct
46 Correct 140 ms 18724 KB Output is correct
47 Correct 139 ms 18808 KB Output is correct
48 Correct 119 ms 17288 KB Output is correct
49 Correct 125 ms 17260 KB Output is correct
50 Correct 118 ms 17304 KB Output is correct
51 Correct 118 ms 17336 KB Output is correct
52 Correct 122 ms 17404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 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 368 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 336 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 324 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 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 320 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 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 0 ms 212 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 368 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 336 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 324 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 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 61 ms 8736 KB Output is correct
24 Correct 62 ms 8760 KB Output is correct
25 Correct 63 ms 8748 KB Output is correct
26 Correct 68 ms 8832 KB Output is correct
27 Correct 55 ms 6456 KB Output is correct
28 Correct 58 ms 8928 KB Output is correct
29 Correct 59 ms 9092 KB Output is correct
30 Correct 61 ms 8992 KB Output is correct
31 Correct 62 ms 9104 KB Output is correct
32 Correct 58 ms 8748 KB Output is correct
33 Correct 66 ms 8828 KB Output is correct
34 Correct 57 ms 8712 KB Output is correct
35 Correct 61 ms 8756 KB Output is correct
36 Correct 58 ms 8752 KB Output is correct
37 Correct 55 ms 8024 KB Output is correct
38 Correct 55 ms 7960 KB Output is correct
39 Correct 50 ms 8836 KB Output is correct
40 Correct 53 ms 8816 KB Output is correct
41 Correct 50 ms 8880 KB Output is correct
42 Correct 50 ms 9004 KB Output is correct
43 Correct 135 ms 18944 KB Output is correct
44 Correct 141 ms 18828 KB Output is correct
45 Correct 137 ms 18732 KB Output is correct
46 Correct 140 ms 18724 KB Output is correct
47 Correct 139 ms 18808 KB Output is correct
48 Correct 119 ms 17288 KB Output is correct
49 Correct 125 ms 17260 KB Output is correct
50 Correct 118 ms 17304 KB Output is correct
51 Correct 118 ms 17336 KB Output is correct
52 Correct 122 ms 17404 KB Output is correct
53 Correct 0 ms 320 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 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 62 ms 8676 KB Output is correct
60 Correct 45 ms 5664 KB Output is correct
61 Correct 42 ms 5896 KB Output is correct
62 Correct 44 ms 6188 KB Output is correct
63 Correct 52 ms 5688 KB Output is correct
64 Correct 50 ms 5448 KB Output is correct
65 Correct 50 ms 5636 KB Output is correct
66 Correct 50 ms 5648 KB Output is correct
67 Correct 50 ms 5556 KB Output is correct
68 Correct 60 ms 8984 KB Output is correct
69 Correct 61 ms 8964 KB Output is correct
70 Correct 61 ms 8896 KB Output is correct
71 Correct 60 ms 8932 KB Output is correct
72 Correct 63 ms 8880 KB Output is correct
73 Correct 63 ms 7984 KB Output is correct
74 Correct 55 ms 7984 KB Output is correct
75 Correct 54 ms 8476 KB Output is correct
76 Correct 55 ms 9052 KB Output is correct
77 Correct 127 ms 17264 KB Output is correct
78 Correct 132 ms 17256 KB Output is correct
79 Correct 130 ms 17316 KB Output is correct
80 Correct 128 ms 17172 KB Output is correct
81 Correct 127 ms 17228 KB Output is correct
82 Correct 121 ms 17628 KB Output is correct
83 Correct 123 ms 17572 KB Output is correct
84 Correct 123 ms 17760 KB Output is correct
85 Correct 127 ms 17584 KB Output is correct
86 Correct 130 ms 17516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 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 368 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 336 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 324 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 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 61 ms 8736 KB Output is correct
24 Correct 62 ms 8760 KB Output is correct
25 Correct 63 ms 8748 KB Output is correct
26 Correct 68 ms 8832 KB Output is correct
27 Correct 55 ms 6456 KB Output is correct
28 Correct 58 ms 8928 KB Output is correct
29 Correct 59 ms 9092 KB Output is correct
30 Correct 61 ms 8992 KB Output is correct
31 Correct 62 ms 9104 KB Output is correct
32 Correct 58 ms 8748 KB Output is correct
33 Correct 66 ms 8828 KB Output is correct
34 Correct 57 ms 8712 KB Output is correct
35 Correct 61 ms 8756 KB Output is correct
36 Correct 58 ms 8752 KB Output is correct
37 Correct 55 ms 8024 KB Output is correct
38 Correct 55 ms 7960 KB Output is correct
39 Correct 50 ms 8836 KB Output is correct
40 Correct 53 ms 8816 KB Output is correct
41 Correct 50 ms 8880 KB Output is correct
42 Correct 50 ms 9004 KB Output is correct
43 Correct 135 ms 18944 KB Output is correct
44 Correct 141 ms 18828 KB Output is correct
45 Correct 137 ms 18732 KB Output is correct
46 Correct 140 ms 18724 KB Output is correct
47 Correct 139 ms 18808 KB Output is correct
48 Correct 119 ms 17288 KB Output is correct
49 Correct 125 ms 17260 KB Output is correct
50 Correct 118 ms 17304 KB Output is correct
51 Correct 118 ms 17336 KB Output is correct
52 Correct 122 ms 17404 KB Output is correct
53 Correct 62 ms 8676 KB Output is correct
54 Correct 45 ms 5664 KB Output is correct
55 Correct 42 ms 5896 KB Output is correct
56 Correct 44 ms 6188 KB Output is correct
57 Correct 52 ms 5688 KB Output is correct
58 Correct 50 ms 5448 KB Output is correct
59 Correct 50 ms 5636 KB Output is correct
60 Correct 50 ms 5648 KB Output is correct
61 Correct 50 ms 5556 KB Output is correct
62 Correct 60 ms 8984 KB Output is correct
63 Correct 61 ms 8964 KB Output is correct
64 Correct 61 ms 8896 KB Output is correct
65 Correct 60 ms 8932 KB Output is correct
66 Correct 63 ms 8880 KB Output is correct
67 Correct 63 ms 7984 KB Output is correct
68 Correct 55 ms 7984 KB Output is correct
69 Correct 54 ms 8476 KB Output is correct
70 Correct 55 ms 9052 KB Output is correct
71 Correct 127 ms 17264 KB Output is correct
72 Correct 132 ms 17256 KB Output is correct
73 Correct 130 ms 17316 KB Output is correct
74 Correct 128 ms 17172 KB Output is correct
75 Correct 127 ms 17228 KB Output is correct
76 Correct 121 ms 17628 KB Output is correct
77 Correct 123 ms 17572 KB Output is correct
78 Correct 123 ms 17760 KB Output is correct
79 Correct 127 ms 17584 KB Output is correct
80 Correct 130 ms 17516 KB Output is correct
81 Correct 0 ms 320 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 340 KB Output is correct
85 Correct 1 ms 340 KB Output is correct
86 Correct 1 ms 340 KB Output is correct
87 Incorrect 71 ms 7220 KB Output isn't correct
88 Halted 0 ms 0 KB -