Submission #253285

# Submission time Handle Problem Language Result Execution time Memory
253285 2020-07-27T15:45:38 Z DystoriaX Wish (LMIO19_noras) C++14
93 / 100
470 ms 21268 KB
#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);
}

__int128 TernarySearch(int a, int b, int dx, int dy){
	__int128 l, r, tp, ret;

	l = ceil((1e8 - a) / abs(dx)), r = ceil((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 = ceil((1e8 - a) / abs(dx)), r = ceil((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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 2 ms 512 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 1 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 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 2 ms 512 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 1 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 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 3 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 124 ms 9952 KB Output is correct
24 Correct 126 ms 9956 KB Output is correct
25 Correct 127 ms 9952 KB Output is correct
26 Correct 140 ms 9956 KB Output is correct
27 Correct 142 ms 5736 KB Output is correct
28 Correct 150 ms 9956 KB Output is correct
29 Correct 149 ms 10080 KB Output is correct
30 Correct 160 ms 10080 KB Output is correct
31 Correct 150 ms 9952 KB Output is correct
32 Correct 214 ms 9952 KB Output is correct
33 Correct 221 ms 10080 KB Output is correct
34 Correct 222 ms 9824 KB Output is correct
35 Correct 216 ms 9824 KB Output is correct
36 Correct 219 ms 9700 KB Output is correct
37 Correct 175 ms 6112 KB Output is correct
38 Correct 190 ms 6132 KB Output is correct
39 Correct 173 ms 5864 KB Output is correct
40 Correct 176 ms 5868 KB Output is correct
41 Correct 176 ms 5932 KB Output is correct
42 Correct 182 ms 5864 KB Output is correct
43 Correct 461 ms 18900 KB Output is correct
44 Correct 465 ms 18900 KB Output is correct
45 Correct 470 ms 18900 KB Output is correct
46 Correct 466 ms 18904 KB Output is correct
47 Correct 470 ms 18900 KB Output is correct
48 Correct 456 ms 19028 KB Output is correct
49 Correct 446 ms 19028 KB Output is correct
50 Correct 444 ms 19028 KB Output is correct
51 Correct 460 ms 19028 KB Output is correct
52 Correct 447 ms 19032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 2 ms 512 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 1 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 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 3 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 3 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 2 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 2 ms 512 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 1 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 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 3 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 124 ms 9952 KB Output is correct
24 Correct 126 ms 9956 KB Output is correct
25 Correct 127 ms 9952 KB Output is correct
26 Correct 140 ms 9956 KB Output is correct
27 Correct 142 ms 5736 KB Output is correct
28 Correct 150 ms 9956 KB Output is correct
29 Correct 149 ms 10080 KB Output is correct
30 Correct 160 ms 10080 KB Output is correct
31 Correct 150 ms 9952 KB Output is correct
32 Correct 214 ms 9952 KB Output is correct
33 Correct 221 ms 10080 KB Output is correct
34 Correct 222 ms 9824 KB Output is correct
35 Correct 216 ms 9824 KB Output is correct
36 Correct 219 ms 9700 KB Output is correct
37 Correct 175 ms 6112 KB Output is correct
38 Correct 190 ms 6132 KB Output is correct
39 Correct 173 ms 5864 KB Output is correct
40 Correct 176 ms 5868 KB Output is correct
41 Correct 176 ms 5932 KB Output is correct
42 Correct 182 ms 5864 KB Output is correct
43 Correct 461 ms 18900 KB Output is correct
44 Correct 465 ms 18900 KB Output is correct
45 Correct 470 ms 18900 KB Output is correct
46 Correct 466 ms 18904 KB Output is correct
47 Correct 470 ms 18900 KB Output is correct
48 Correct 456 ms 19028 KB Output is correct
49 Correct 446 ms 19028 KB Output is correct
50 Correct 444 ms 19028 KB Output is correct
51 Correct 460 ms 19028 KB Output is correct
52 Correct 447 ms 19032 KB Output is correct
53 Correct 136 ms 9832 KB Output is correct
54 Correct 139 ms 5736 KB Output is correct
55 Correct 125 ms 7144 KB Output is correct
56 Correct 127 ms 7520 KB Output is correct
57 Correct 184 ms 7568 KB Output is correct
58 Correct 186 ms 7528 KB Output is correct
59 Correct 187 ms 7400 KB Output is correct
60 Correct 180 ms 7400 KB Output is correct
61 Correct 181 ms 7400 KB Output is correct
62 Correct 228 ms 11232 KB Output is correct
63 Correct 228 ms 11236 KB Output is correct
64 Correct 236 ms 11232 KB Output is correct
65 Correct 220 ms 11364 KB Output is correct
66 Correct 219 ms 11388 KB Output is correct
67 Correct 187 ms 7264 KB Output is correct
68 Correct 184 ms 11740 KB Output is correct
69 Correct 191 ms 11616 KB Output is correct
70 Correct 177 ms 7536 KB Output is correct
71 Correct 465 ms 21244 KB Output is correct
72 Correct 460 ms 21204 KB Output is correct
73 Correct 462 ms 21268 KB Output is correct
74 Correct 461 ms 21072 KB Output is correct
75 Correct 446 ms 21180 KB Output is correct
76 Correct 454 ms 20948 KB Output is correct
77 Correct 460 ms 20948 KB Output is correct
78 Correct 446 ms 21076 KB Output is correct
79 Correct 460 ms 20948 KB Output is correct
80 Correct 457 ms 20948 KB Output is correct
81 Correct 0 ms 384 KB Output is correct
82 Correct 3 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 2 ms 512 KB Output is correct
86 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 2 ms 512 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 1 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 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 3 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 124 ms 9952 KB Output is correct
24 Correct 126 ms 9956 KB Output is correct
25 Correct 127 ms 9952 KB Output is correct
26 Correct 140 ms 9956 KB Output is correct
27 Correct 142 ms 5736 KB Output is correct
28 Correct 150 ms 9956 KB Output is correct
29 Correct 149 ms 10080 KB Output is correct
30 Correct 160 ms 10080 KB Output is correct
31 Correct 150 ms 9952 KB Output is correct
32 Correct 214 ms 9952 KB Output is correct
33 Correct 221 ms 10080 KB Output is correct
34 Correct 222 ms 9824 KB Output is correct
35 Correct 216 ms 9824 KB Output is correct
36 Correct 219 ms 9700 KB Output is correct
37 Correct 175 ms 6112 KB Output is correct
38 Correct 190 ms 6132 KB Output is correct
39 Correct 173 ms 5864 KB Output is correct
40 Correct 176 ms 5868 KB Output is correct
41 Correct 176 ms 5932 KB Output is correct
42 Correct 182 ms 5864 KB Output is correct
43 Correct 461 ms 18900 KB Output is correct
44 Correct 465 ms 18900 KB Output is correct
45 Correct 470 ms 18900 KB Output is correct
46 Correct 466 ms 18904 KB Output is correct
47 Correct 470 ms 18900 KB Output is correct
48 Correct 456 ms 19028 KB Output is correct
49 Correct 446 ms 19028 KB Output is correct
50 Correct 444 ms 19028 KB Output is correct
51 Correct 460 ms 19028 KB Output is correct
52 Correct 447 ms 19032 KB Output is correct
53 Correct 136 ms 9832 KB Output is correct
54 Correct 139 ms 5736 KB Output is correct
55 Correct 125 ms 7144 KB Output is correct
56 Correct 127 ms 7520 KB Output is correct
57 Correct 184 ms 7568 KB Output is correct
58 Correct 186 ms 7528 KB Output is correct
59 Correct 187 ms 7400 KB Output is correct
60 Correct 180 ms 7400 KB Output is correct
61 Correct 181 ms 7400 KB Output is correct
62 Correct 228 ms 11232 KB Output is correct
63 Correct 228 ms 11236 KB Output is correct
64 Correct 236 ms 11232 KB Output is correct
65 Correct 220 ms 11364 KB Output is correct
66 Correct 219 ms 11388 KB Output is correct
67 Correct 187 ms 7264 KB Output is correct
68 Correct 184 ms 11740 KB Output is correct
69 Correct 191 ms 11616 KB Output is correct
70 Correct 177 ms 7536 KB Output is correct
71 Correct 465 ms 21244 KB Output is correct
72 Correct 460 ms 21204 KB Output is correct
73 Correct 462 ms 21268 KB Output is correct
74 Correct 461 ms 21072 KB Output is correct
75 Correct 446 ms 21180 KB Output is correct
76 Correct 454 ms 20948 KB Output is correct
77 Correct 460 ms 20948 KB Output is correct
78 Correct 446 ms 21076 KB Output is correct
79 Correct 460 ms 20948 KB Output is correct
80 Correct 457 ms 20948 KB Output is correct
81 Correct 190 ms 7684 KB Output is correct
82 Incorrect 183 ms 7656 KB Output isn't correct
83 Halted 0 ms 0 KB -