Submission #253281

# Submission time Handle Problem Language Result Execution time Memory
253281 2020-07-27T15:43:31 Z DystoriaX Wish (LMIO19_noras) C++14
61 / 100
245 ms 12780 KB
#include <bits/stdc++.h>

#define __int128 long long

using namespace std;

typedef pair<long long, int> pii;

int n, r;
int a[200010], b[200010], dx[200010], dy[200010];
int pref[200010];

vector<pii> v;

long long sq(long long x){
	return x * x;
}

long long sqDist(long long dx, long long dy){
	return sq(dx) + sq(dy);
}

bool check(long long dx, long long dy){
	return sqDist(dx, dy) <= sq(r);
}

bool check(long long d){
	return d <= sq(r);
}

long long TernarySearch(int a, int b, int dx, int dy){
	long long 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){
		long long 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;
}

long long SearchLeft(int a, int b, int dx, int dy, long long pvt){
	long long l, r;

	l = 0;
	r = pvt;

	while(l <= r){
		long long m = (l + r) >> 1;

		if(check(a + 1LL * m * dx, b + 1LL * m * dy)) r = m - 1;
		else l = m + 1;
	}

	return l;
}

long long SearchRight(int a, int b, int dx, int dy, long long pvt){
	long long l, r;
	l = ceil((1e8 - a) / abs(dx)), r = ceil((1e8 - b) / abs(dy));

	r = max(l, r);

	l = pvt;

	while(l <= r){
		long long 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 1 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 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 67 ms 6896 KB Output is correct
24 Correct 67 ms 7024 KB Output is correct
25 Correct 75 ms 6888 KB Output is correct
26 Correct 72 ms 7080 KB Output is correct
27 Correct 82 ms 5228 KB Output is correct
28 Correct 76 ms 7144 KB Output is correct
29 Correct 74 ms 7152 KB Output is correct
30 Correct 75 ms 7152 KB Output is correct
31 Correct 76 ms 7144 KB Output is correct
32 Correct 108 ms 7020 KB Output is correct
33 Correct 109 ms 7016 KB Output is correct
34 Correct 106 ms 7144 KB Output is correct
35 Correct 117 ms 7020 KB Output is correct
36 Correct 110 ms 7016 KB Output is correct
37 Correct 76 ms 5608 KB Output is correct
38 Correct 78 ms 5608 KB Output is correct
39 Correct 74 ms 5360 KB Output is correct
40 Correct 83 ms 5356 KB Output is correct
41 Correct 79 ms 5384 KB Output is correct
42 Correct 88 ms 5488 KB Output is correct
43 Correct 239 ms 12640 KB Output is correct
44 Correct 237 ms 12768 KB Output is correct
45 Correct 245 ms 12640 KB Output is correct
46 Correct 236 ms 12640 KB Output is correct
47 Correct 235 ms 12640 KB Output is correct
48 Correct 215 ms 12780 KB Output is correct
49 Correct 211 ms 12772 KB Output is correct
50 Correct 214 ms 12768 KB Output is correct
51 Correct 213 ms 12768 KB Output is correct
52 Correct 212 ms 12768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 67 ms 6896 KB Output is correct
24 Correct 67 ms 7024 KB Output is correct
25 Correct 75 ms 6888 KB Output is correct
26 Correct 72 ms 7080 KB Output is correct
27 Correct 82 ms 5228 KB Output is correct
28 Correct 76 ms 7144 KB Output is correct
29 Correct 74 ms 7152 KB Output is correct
30 Correct 75 ms 7152 KB Output is correct
31 Correct 76 ms 7144 KB Output is correct
32 Correct 108 ms 7020 KB Output is correct
33 Correct 109 ms 7016 KB Output is correct
34 Correct 106 ms 7144 KB Output is correct
35 Correct 117 ms 7020 KB Output is correct
36 Correct 110 ms 7016 KB Output is correct
37 Correct 76 ms 5608 KB Output is correct
38 Correct 78 ms 5608 KB Output is correct
39 Correct 74 ms 5360 KB Output is correct
40 Correct 83 ms 5356 KB Output is correct
41 Correct 79 ms 5384 KB Output is correct
42 Correct 88 ms 5488 KB Output is correct
43 Correct 239 ms 12640 KB Output is correct
44 Correct 237 ms 12768 KB Output is correct
45 Correct 245 ms 12640 KB Output is correct
46 Correct 236 ms 12640 KB Output is correct
47 Correct 235 ms 12640 KB Output is correct
48 Correct 215 ms 12780 KB Output is correct
49 Correct 211 ms 12772 KB Output is correct
50 Correct 214 ms 12768 KB Output is correct
51 Correct 213 ms 12768 KB Output is correct
52 Correct 212 ms 12768 KB Output is correct
53 Correct 71 ms 6888 KB Output is correct
54 Incorrect 79 ms 5392 KB Output isn't correct
55 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 67 ms 6896 KB Output is correct
24 Correct 67 ms 7024 KB Output is correct
25 Correct 75 ms 6888 KB Output is correct
26 Correct 72 ms 7080 KB Output is correct
27 Correct 82 ms 5228 KB Output is correct
28 Correct 76 ms 7144 KB Output is correct
29 Correct 74 ms 7152 KB Output is correct
30 Correct 75 ms 7152 KB Output is correct
31 Correct 76 ms 7144 KB Output is correct
32 Correct 108 ms 7020 KB Output is correct
33 Correct 109 ms 7016 KB Output is correct
34 Correct 106 ms 7144 KB Output is correct
35 Correct 117 ms 7020 KB Output is correct
36 Correct 110 ms 7016 KB Output is correct
37 Correct 76 ms 5608 KB Output is correct
38 Correct 78 ms 5608 KB Output is correct
39 Correct 74 ms 5360 KB Output is correct
40 Correct 83 ms 5356 KB Output is correct
41 Correct 79 ms 5384 KB Output is correct
42 Correct 88 ms 5488 KB Output is correct
43 Correct 239 ms 12640 KB Output is correct
44 Correct 237 ms 12768 KB Output is correct
45 Correct 245 ms 12640 KB Output is correct
46 Correct 236 ms 12640 KB Output is correct
47 Correct 235 ms 12640 KB Output is correct
48 Correct 215 ms 12780 KB Output is correct
49 Correct 211 ms 12772 KB Output is correct
50 Correct 214 ms 12768 KB Output is correct
51 Correct 213 ms 12768 KB Output is correct
52 Correct 212 ms 12768 KB Output is correct
53 Correct 71 ms 6888 KB Output is correct
54 Incorrect 79 ms 5392 KB Output isn't correct
55 Halted 0 ms 0 KB -