#include <bits/stdc++.h>
using namespace std;
typedef pair<__int128, int> pii;
int n, r;
int a[200010], b[200010], dx[200010], dy[200010];
int pref[200010];
vector<pii> v;
__int128 sq(__int128 x){
return x * x;
}
__int128 sqDist(__int128 dx, __int128 dy){
return sq(dx) + sq(dy);
}
bool check(__int128 dx, __int128 dy){
return sqDist(dx, dy) <= sq(r);
}
bool check(__int128 d){
return d <= sq(r);
}
long long ceila(long long a, long long b){
if(b == 0) return 0;
return a / b + (a % b > 0);
}
__int128 TernarySearch(int a, int b, int dx, int dy){
__int128 l, r, tp, ret;
l = ceila((1e8 - a), abs(dx)), r = ceila((1e8 - b), abs(dy));
r = max(l, r);
l = 0;
if(r < 0) return -1;
tp = 4e18; ret = -1;
while(l <= r){
__int128 m1, m2, v1, v2;
m1 = l + (r - l) / 3;
m2 = r - (r - l) / 3;
v1 = sqDist(a + 1LL * m1 * dx, b + 1LL * m1 * dy);
v2 = sqDist(a + 1LL * m2 * dx, b + 1LL * m2 * dy);
if(v1 > v2){
l = m1 + 1;
if(tp > v2){
ret = m2;
tp = v2;
}
} else {
r = m2 - 1;
if(tp > v1){
ret = m1;
tp = v1;
}
}
}
if(check(tp)) return ret;
else return -1;
}
__int128 SearchLeft(int a, int b, int dx, int dy, __int128 pvt){
__int128 l, r;
l = 0;
r = pvt;
while(l <= r){
__int128 m = (l + r) >> 1;
if(check(a + 1LL * m * dx, b + 1LL * m * dy)) r = m - 1;
else l = m + 1;
}
return l;
}
__int128 SearchRight(int a, int b, int dx, int dy, __int128 pvt){
__int128 l, r;
l = ceila((1e8 - a), abs(dx)), r = ceila((1e8 - b), abs(dy));
r = max(l, r);
l = pvt;
while(l <= r){
__int128 m = (l + r) >> 1;
if(check(a + 1LL * m * dx, b + 1LL * m * dy)) l = m + 1;
else r = m - 1;
}
return r;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> n >> r;
for(int i = 1; i <= n; i++){
cin >> a[i] >> b[i] >> dx[i] >> dy[i];
dx[i] -= a[i];
dy[i] -= b[i];
long long mn, mx, pvt;
pvt = TernarySearch(a[i], b[i], dx[i], dy[i]);
// cerr << i << ":\n";
// cerr << pvt << "\n";
if(pvt == -1) continue;
mn = SearchLeft(a[i], b[i], dx[i], dy[i], pvt);
mx = SearchRight(a[i], b[i], dx[i], dy[i], pvt);
if(mn > mx) swap(mn, mx);
// cerr << mn << " " << mx << "\n";
if(mx >= 0 && mn <= mx){
// cerr << mn << " " << mx << "\n";
assert(check(a[i] + 1LL * mn * dx[i], b[i] + 1LL * mn * dy[i]));
assert(check(a[i] + 1LL * mx * dx[i], b[i] + 1LL * mx * dy[i]));
v.emplace_back(max(0LL, mn), 1);
v.emplace_back(mx + 1, -1);
}
// for(int k = 0; k <= 20000; k++){
// if(sq(a[i] + 1LL * k * dx[i]) + sq(b[i] + 1LL * k * dy[i]) <= sq(r)) pref[k]++;
// }
}
int ans = 0, cnt = 0;
sort(v.begin(), v.end());
for(int i = 0; i < (int) v.size(); i++){
int j = i;
while(j < (int) v.size() && v[i].first == v[j].first){
cnt += v[j++].second;
}
ans = max(ans, cnt);
i = j - 1;
}
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
512 KB |
Output is correct |
15 |
Correct |
3 ms |
512 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
3 ms |
512 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
2 ms |
512 KB |
Output is correct |
20 |
Correct |
2 ms |
512 KB |
Output is correct |
21 |
Correct |
2 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
512 KB |
Output is correct |
15 |
Correct |
3 ms |
512 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
3 ms |
512 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
2 ms |
512 KB |
Output is correct |
20 |
Correct |
2 ms |
512 KB |
Output is correct |
21 |
Correct |
2 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
23 |
Correct |
120 ms |
10080 KB |
Output is correct |
24 |
Correct |
187 ms |
10080 KB |
Output is correct |
25 |
Correct |
124 ms |
10208 KB |
Output is correct |
26 |
Correct |
130 ms |
10208 KB |
Output is correct |
27 |
Correct |
133 ms |
5864 KB |
Output is correct |
28 |
Correct |
147 ms |
10208 KB |
Output is correct |
29 |
Correct |
148 ms |
10208 KB |
Output is correct |
30 |
Correct |
161 ms |
10212 KB |
Output is correct |
31 |
Correct |
158 ms |
10208 KB |
Output is correct |
32 |
Correct |
232 ms |
10208 KB |
Output is correct |
33 |
Correct |
226 ms |
10224 KB |
Output is correct |
34 |
Correct |
218 ms |
9952 KB |
Output is correct |
35 |
Correct |
222 ms |
9952 KB |
Output is correct |
36 |
Correct |
216 ms |
9952 KB |
Output is correct |
37 |
Correct |
180 ms |
6240 KB |
Output is correct |
38 |
Correct |
178 ms |
6244 KB |
Output is correct |
39 |
Correct |
178 ms |
6136 KB |
Output is correct |
40 |
Correct |
179 ms |
5992 KB |
Output is correct |
41 |
Correct |
178 ms |
5992 KB |
Output is correct |
42 |
Correct |
183 ms |
6120 KB |
Output is correct |
43 |
Correct |
479 ms |
19412 KB |
Output is correct |
44 |
Correct |
473 ms |
19332 KB |
Output is correct |
45 |
Correct |
481 ms |
19432 KB |
Output is correct |
46 |
Correct |
477 ms |
19416 KB |
Output is correct |
47 |
Correct |
472 ms |
19412 KB |
Output is correct |
48 |
Correct |
439 ms |
19520 KB |
Output is correct |
49 |
Correct |
450 ms |
19392 KB |
Output is correct |
50 |
Correct |
450 ms |
19412 KB |
Output is correct |
51 |
Correct |
441 ms |
19544 KB |
Output is correct |
52 |
Correct |
442 ms |
19572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
512 KB |
Output is correct |
15 |
Correct |
3 ms |
512 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
3 ms |
512 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
2 ms |
512 KB |
Output is correct |
20 |
Correct |
2 ms |
512 KB |
Output is correct |
21 |
Correct |
2 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
23 |
Correct |
0 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
512 KB |
Output is correct |
25 |
Correct |
3 ms |
512 KB |
Output is correct |
26 |
Correct |
2 ms |
512 KB |
Output is correct |
27 |
Correct |
3 ms |
512 KB |
Output is correct |
28 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
512 KB |
Output is correct |
15 |
Correct |
3 ms |
512 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
3 ms |
512 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
2 ms |
512 KB |
Output is correct |
20 |
Correct |
2 ms |
512 KB |
Output is correct |
21 |
Correct |
2 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
23 |
Correct |
120 ms |
10080 KB |
Output is correct |
24 |
Correct |
187 ms |
10080 KB |
Output is correct |
25 |
Correct |
124 ms |
10208 KB |
Output is correct |
26 |
Correct |
130 ms |
10208 KB |
Output is correct |
27 |
Correct |
133 ms |
5864 KB |
Output is correct |
28 |
Correct |
147 ms |
10208 KB |
Output is correct |
29 |
Correct |
148 ms |
10208 KB |
Output is correct |
30 |
Correct |
161 ms |
10212 KB |
Output is correct |
31 |
Correct |
158 ms |
10208 KB |
Output is correct |
32 |
Correct |
232 ms |
10208 KB |
Output is correct |
33 |
Correct |
226 ms |
10224 KB |
Output is correct |
34 |
Correct |
218 ms |
9952 KB |
Output is correct |
35 |
Correct |
222 ms |
9952 KB |
Output is correct |
36 |
Correct |
216 ms |
9952 KB |
Output is correct |
37 |
Correct |
180 ms |
6240 KB |
Output is correct |
38 |
Correct |
178 ms |
6244 KB |
Output is correct |
39 |
Correct |
178 ms |
6136 KB |
Output is correct |
40 |
Correct |
179 ms |
5992 KB |
Output is correct |
41 |
Correct |
178 ms |
5992 KB |
Output is correct |
42 |
Correct |
183 ms |
6120 KB |
Output is correct |
43 |
Correct |
479 ms |
19412 KB |
Output is correct |
44 |
Correct |
473 ms |
19332 KB |
Output is correct |
45 |
Correct |
481 ms |
19432 KB |
Output is correct |
46 |
Correct |
477 ms |
19416 KB |
Output is correct |
47 |
Correct |
472 ms |
19412 KB |
Output is correct |
48 |
Correct |
439 ms |
19520 KB |
Output is correct |
49 |
Correct |
450 ms |
19392 KB |
Output is correct |
50 |
Correct |
450 ms |
19412 KB |
Output is correct |
51 |
Correct |
441 ms |
19544 KB |
Output is correct |
52 |
Correct |
442 ms |
19572 KB |
Output is correct |
53 |
Correct |
129 ms |
9952 KB |
Output is correct |
54 |
Correct |
128 ms |
5864 KB |
Output is correct |
55 |
Correct |
124 ms |
5864 KB |
Output is correct |
56 |
Correct |
118 ms |
5728 KB |
Output is correct |
57 |
Correct |
181 ms |
5864 KB |
Output is correct |
58 |
Correct |
177 ms |
5864 KB |
Output is correct |
59 |
Correct |
182 ms |
6008 KB |
Output is correct |
60 |
Correct |
181 ms |
5992 KB |
Output is correct |
61 |
Correct |
179 ms |
5964 KB |
Output is correct |
62 |
Correct |
227 ms |
10080 KB |
Output is correct |
63 |
Correct |
225 ms |
9952 KB |
Output is correct |
64 |
Correct |
222 ms |
9952 KB |
Output is correct |
65 |
Correct |
225 ms |
9952 KB |
Output is correct |
66 |
Correct |
225 ms |
9964 KB |
Output is correct |
67 |
Correct |
171 ms |
5984 KB |
Output is correct |
68 |
Correct |
190 ms |
10508 KB |
Output is correct |
69 |
Correct |
195 ms |
10348 KB |
Output is correct |
70 |
Correct |
180 ms |
6128 KB |
Output is correct |
71 |
Correct |
449 ms |
19588 KB |
Output is correct |
72 |
Correct |
470 ms |
19668 KB |
Output is correct |
73 |
Correct |
446 ms |
19668 KB |
Output is correct |
74 |
Correct |
471 ms |
19672 KB |
Output is correct |
75 |
Correct |
452 ms |
19720 KB |
Output is correct |
76 |
Correct |
448 ms |
19576 KB |
Output is correct |
77 |
Correct |
436 ms |
19540 KB |
Output is correct |
78 |
Correct |
448 ms |
19540 KB |
Output is correct |
79 |
Correct |
433 ms |
19540 KB |
Output is correct |
80 |
Correct |
452 ms |
19572 KB |
Output is correct |
81 |
Correct |
0 ms |
384 KB |
Output is correct |
82 |
Correct |
2 ms |
512 KB |
Output is correct |
83 |
Correct |
3 ms |
512 KB |
Output is correct |
84 |
Correct |
2 ms |
512 KB |
Output is correct |
85 |
Correct |
3 ms |
512 KB |
Output is correct |
86 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
512 KB |
Output is correct |
15 |
Correct |
3 ms |
512 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
3 ms |
512 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
2 ms |
512 KB |
Output is correct |
20 |
Correct |
2 ms |
512 KB |
Output is correct |
21 |
Correct |
2 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
23 |
Correct |
120 ms |
10080 KB |
Output is correct |
24 |
Correct |
187 ms |
10080 KB |
Output is correct |
25 |
Correct |
124 ms |
10208 KB |
Output is correct |
26 |
Correct |
130 ms |
10208 KB |
Output is correct |
27 |
Correct |
133 ms |
5864 KB |
Output is correct |
28 |
Correct |
147 ms |
10208 KB |
Output is correct |
29 |
Correct |
148 ms |
10208 KB |
Output is correct |
30 |
Correct |
161 ms |
10212 KB |
Output is correct |
31 |
Correct |
158 ms |
10208 KB |
Output is correct |
32 |
Correct |
232 ms |
10208 KB |
Output is correct |
33 |
Correct |
226 ms |
10224 KB |
Output is correct |
34 |
Correct |
218 ms |
9952 KB |
Output is correct |
35 |
Correct |
222 ms |
9952 KB |
Output is correct |
36 |
Correct |
216 ms |
9952 KB |
Output is correct |
37 |
Correct |
180 ms |
6240 KB |
Output is correct |
38 |
Correct |
178 ms |
6244 KB |
Output is correct |
39 |
Correct |
178 ms |
6136 KB |
Output is correct |
40 |
Correct |
179 ms |
5992 KB |
Output is correct |
41 |
Correct |
178 ms |
5992 KB |
Output is correct |
42 |
Correct |
183 ms |
6120 KB |
Output is correct |
43 |
Correct |
479 ms |
19412 KB |
Output is correct |
44 |
Correct |
473 ms |
19332 KB |
Output is correct |
45 |
Correct |
481 ms |
19432 KB |
Output is correct |
46 |
Correct |
477 ms |
19416 KB |
Output is correct |
47 |
Correct |
472 ms |
19412 KB |
Output is correct |
48 |
Correct |
439 ms |
19520 KB |
Output is correct |
49 |
Correct |
450 ms |
19392 KB |
Output is correct |
50 |
Correct |
450 ms |
19412 KB |
Output is correct |
51 |
Correct |
441 ms |
19544 KB |
Output is correct |
52 |
Correct |
442 ms |
19572 KB |
Output is correct |
53 |
Correct |
129 ms |
9952 KB |
Output is correct |
54 |
Correct |
128 ms |
5864 KB |
Output is correct |
55 |
Correct |
124 ms |
5864 KB |
Output is correct |
56 |
Correct |
118 ms |
5728 KB |
Output is correct |
57 |
Correct |
181 ms |
5864 KB |
Output is correct |
58 |
Correct |
177 ms |
5864 KB |
Output is correct |
59 |
Correct |
182 ms |
6008 KB |
Output is correct |
60 |
Correct |
181 ms |
5992 KB |
Output is correct |
61 |
Correct |
179 ms |
5964 KB |
Output is correct |
62 |
Correct |
227 ms |
10080 KB |
Output is correct |
63 |
Correct |
225 ms |
9952 KB |
Output is correct |
64 |
Correct |
222 ms |
9952 KB |
Output is correct |
65 |
Correct |
225 ms |
9952 KB |
Output is correct |
66 |
Correct |
225 ms |
9964 KB |
Output is correct |
67 |
Correct |
171 ms |
5984 KB |
Output is correct |
68 |
Correct |
190 ms |
10508 KB |
Output is correct |
69 |
Correct |
195 ms |
10348 KB |
Output is correct |
70 |
Correct |
180 ms |
6128 KB |
Output is correct |
71 |
Correct |
449 ms |
19588 KB |
Output is correct |
72 |
Correct |
470 ms |
19668 KB |
Output is correct |
73 |
Correct |
446 ms |
19668 KB |
Output is correct |
74 |
Correct |
471 ms |
19672 KB |
Output is correct |
75 |
Correct |
452 ms |
19720 KB |
Output is correct |
76 |
Correct |
448 ms |
19576 KB |
Output is correct |
77 |
Correct |
436 ms |
19540 KB |
Output is correct |
78 |
Correct |
448 ms |
19540 KB |
Output is correct |
79 |
Correct |
433 ms |
19540 KB |
Output is correct |
80 |
Correct |
452 ms |
19572 KB |
Output is correct |
81 |
Correct |
191 ms |
6124 KB |
Output is correct |
82 |
Incorrect |
186 ms |
6112 KB |
Output isn't correct |
83 |
Halted |
0 ms |
0 KB |
- |