Submission #375618

# Submission time Handle Problem Language Result Execution time Memory
375618 2021-03-09T15:35:57 Z mode149256 Wish (LMIO19_noras) C++17
100 / 100
377 ms 15084 KB
/*input
2 1
-3 -2 -1 -1
-2 2 -1 1
*/
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second

using ll = long long;
using pl = pair<ll, ll>;

struct beam {
	pl prad;
	pl dxy; // {dx, dy}
};
int N;
ll R;

ll dis(pl a, pl b) { // squared distance
	return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}

// 0th second yra prad
pl getnth(ll n, beam b) {
	return {b.prad.x + n * b.dxy.x, b.prad.y + n * b.dxy.y};
}
vector<beam> sk;

ll getINF(beam b) {
	return ((ll)200000007) / max(abs(b.dxy.x), abs(b.dxy.y));
}
pl og = {0, 0};

ll closest(beam b) {
	ll l = 0;
	ll h = getINF(b);
	ll m;

	while (l < h) {
		m = (l + h) / 2;

		pl n1 = getnth(m, b);
		pl n2 = getnth(m + 1, b);

		ll d1 = dis(n1, og);
		ll d2 = dis(n2, og);

		if (d1 == d2) {
			return m;
		} else if (d1 < d2) {
			h = m;
		} else {
			l = m + 1;
		}
	}

	return l;
}

ll getFirst(beam b, ll best) {
	ll l = 0;
	ll h = best;
	ll m;
	while (l < h) {
		m = (l + h) / 2;

		pl n1 = getnth(m, b);
		ll d1 = dis(n1, og);

		if (d1 <= R * R) {
			h = m;
		} else {
			l = m + 1;
		}
	}
	return l;
}

ll getLast(beam b, ll best) {
	ll l = best;
	ll h = getINF(b);
	ll m;
	while (l < h) {
		m = (l + h + 1) / 2;

		pl n1 = getnth(m, b);
		ll d1 = dis(n1, og);

		if (d1 <= R * R) {
			l = m;
		} else {
			h = m - 1;
		}
	}
	return l;
}

int main() {
	cin >> N >> R;
	sk.resize(N);
	for (int i = 0; i < N; ++i)
	{
		ll a, b, c, d;
		cin >> a >> b >> c >> d;
		sk[i] = beam{{a, b}, {c - a, d - b}};
	}

	vector<pl> inter;

	for (auto b : sk) {
		ll best = closest(b);
		if (dis(getnth(best, b), og) > R * R) {
			continue;
		}

		ll pirm = getFirst(b, best);
		ll gal = getLast(b, best);

		inter.emplace_back(pirm, +1);
		inter.emplace_back(gal + 1, -1);
		//[pirm, gal]
	}

	sort(inter.begin(), inter.end());

	ll ats = 0;
	ll curr = 0;

	int j = 0;
	while (j < (int)inter.size()) {
		ll dabar = inter[j].x;
		while (j < (int)inter.size() && inter[j].x == dabar) {
			curr += inter[j].y;
			j++;
		}

		ats = max(ats, curr);
	}
	cout << ats << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 236 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 4 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 3 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 236 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 4 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 3 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 128 ms 7644 KB Output is correct
24 Correct 134 ms 7708 KB Output is correct
25 Correct 128 ms 7772 KB Output is correct
26 Correct 129 ms 7644 KB Output is correct
27 Correct 132 ms 5600 KB Output is correct
28 Correct 141 ms 7792 KB Output is correct
29 Correct 136 ms 7644 KB Output is correct
30 Correct 137 ms 7644 KB Output is correct
31 Correct 139 ms 7772 KB Output is correct
32 Correct 162 ms 7644 KB Output is correct
33 Correct 160 ms 7644 KB Output is correct
34 Correct 162 ms 7644 KB Output is correct
35 Correct 161 ms 7644 KB Output is correct
36 Correct 163 ms 7772 KB Output is correct
37 Correct 148 ms 5728 KB Output is correct
38 Correct 133 ms 5600 KB Output is correct
39 Correct 132 ms 5728 KB Output is correct
40 Correct 131 ms 5600 KB Output is correct
41 Correct 133 ms 5728 KB Output is correct
42 Correct 134 ms 5600 KB Output is correct
43 Correct 367 ms 14932 KB Output is correct
44 Correct 373 ms 14932 KB Output is correct
45 Correct 369 ms 15060 KB Output is correct
46 Correct 377 ms 14932 KB Output is correct
47 Correct 369 ms 15084 KB Output is correct
48 Correct 324 ms 14932 KB Output is correct
49 Correct 338 ms 14932 KB Output is correct
50 Correct 325 ms 14932 KB Output is correct
51 Correct 332 ms 14932 KB Output is correct
52 Correct 323 ms 14928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 236 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 4 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 3 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 3 ms 364 KB Output is correct
28 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 236 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 4 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 3 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 128 ms 7644 KB Output is correct
24 Correct 134 ms 7708 KB Output is correct
25 Correct 128 ms 7772 KB Output is correct
26 Correct 129 ms 7644 KB Output is correct
27 Correct 132 ms 5600 KB Output is correct
28 Correct 141 ms 7792 KB Output is correct
29 Correct 136 ms 7644 KB Output is correct
30 Correct 137 ms 7644 KB Output is correct
31 Correct 139 ms 7772 KB Output is correct
32 Correct 162 ms 7644 KB Output is correct
33 Correct 160 ms 7644 KB Output is correct
34 Correct 162 ms 7644 KB Output is correct
35 Correct 161 ms 7644 KB Output is correct
36 Correct 163 ms 7772 KB Output is correct
37 Correct 148 ms 5728 KB Output is correct
38 Correct 133 ms 5600 KB Output is correct
39 Correct 132 ms 5728 KB Output is correct
40 Correct 131 ms 5600 KB Output is correct
41 Correct 133 ms 5728 KB Output is correct
42 Correct 134 ms 5600 KB Output is correct
43 Correct 367 ms 14932 KB Output is correct
44 Correct 373 ms 14932 KB Output is correct
45 Correct 369 ms 15060 KB Output is correct
46 Correct 377 ms 14932 KB Output is correct
47 Correct 369 ms 15084 KB Output is correct
48 Correct 324 ms 14932 KB Output is correct
49 Correct 338 ms 14932 KB Output is correct
50 Correct 325 ms 14932 KB Output is correct
51 Correct 332 ms 14932 KB Output is correct
52 Correct 323 ms 14928 KB Output is correct
53 Correct 1 ms 364 KB Output is correct
54 Correct 2 ms 364 KB Output is correct
55 Correct 2 ms 364 KB Output is correct
56 Correct 2 ms 364 KB Output is correct
57 Correct 3 ms 364 KB Output is correct
58 Correct 2 ms 364 KB Output is correct
59 Correct 130 ms 7644 KB Output is correct
60 Correct 148 ms 5600 KB Output is correct
61 Correct 137 ms 5600 KB Output is correct
62 Correct 133 ms 5600 KB Output is correct
63 Correct 154 ms 5600 KB Output is correct
64 Correct 153 ms 5600 KB Output is correct
65 Correct 159 ms 5600 KB Output is correct
66 Correct 159 ms 5600 KB Output is correct
67 Correct 167 ms 5600 KB Output is correct
68 Correct 171 ms 7792 KB Output is correct
69 Correct 166 ms 7644 KB Output is correct
70 Correct 167 ms 7644 KB Output is correct
71 Correct 182 ms 7644 KB Output is correct
72 Correct 166 ms 7644 KB Output is correct
73 Correct 131 ms 5728 KB Output is correct
74 Correct 138 ms 7644 KB Output is correct
75 Correct 137 ms 7792 KB Output is correct
76 Correct 145 ms 5728 KB Output is correct
77 Correct 357 ms 14888 KB Output is correct
78 Correct 352 ms 14932 KB Output is correct
79 Correct 362 ms 14932 KB Output is correct
80 Correct 356 ms 14928 KB Output is correct
81 Correct 355 ms 14932 KB Output is correct
82 Correct 336 ms 14936 KB Output is correct
83 Correct 336 ms 14932 KB Output is correct
84 Correct 338 ms 14932 KB Output is correct
85 Correct 343 ms 14932 KB Output is correct
86 Correct 335 ms 14964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 236 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 4 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 3 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 128 ms 7644 KB Output is correct
24 Correct 134 ms 7708 KB Output is correct
25 Correct 128 ms 7772 KB Output is correct
26 Correct 129 ms 7644 KB Output is correct
27 Correct 132 ms 5600 KB Output is correct
28 Correct 141 ms 7792 KB Output is correct
29 Correct 136 ms 7644 KB Output is correct
30 Correct 137 ms 7644 KB Output is correct
31 Correct 139 ms 7772 KB Output is correct
32 Correct 162 ms 7644 KB Output is correct
33 Correct 160 ms 7644 KB Output is correct
34 Correct 162 ms 7644 KB Output is correct
35 Correct 161 ms 7644 KB Output is correct
36 Correct 163 ms 7772 KB Output is correct
37 Correct 148 ms 5728 KB Output is correct
38 Correct 133 ms 5600 KB Output is correct
39 Correct 132 ms 5728 KB Output is correct
40 Correct 131 ms 5600 KB Output is correct
41 Correct 133 ms 5728 KB Output is correct
42 Correct 134 ms 5600 KB Output is correct
43 Correct 367 ms 14932 KB Output is correct
44 Correct 373 ms 14932 KB Output is correct
45 Correct 369 ms 15060 KB Output is correct
46 Correct 377 ms 14932 KB Output is correct
47 Correct 369 ms 15084 KB Output is correct
48 Correct 324 ms 14932 KB Output is correct
49 Correct 338 ms 14932 KB Output is correct
50 Correct 325 ms 14932 KB Output is correct
51 Correct 332 ms 14932 KB Output is correct
52 Correct 323 ms 14928 KB Output is correct
53 Correct 130 ms 7644 KB Output is correct
54 Correct 148 ms 5600 KB Output is correct
55 Correct 137 ms 5600 KB Output is correct
56 Correct 133 ms 5600 KB Output is correct
57 Correct 154 ms 5600 KB Output is correct
58 Correct 153 ms 5600 KB Output is correct
59 Correct 159 ms 5600 KB Output is correct
60 Correct 159 ms 5600 KB Output is correct
61 Correct 167 ms 5600 KB Output is correct
62 Correct 171 ms 7792 KB Output is correct
63 Correct 166 ms 7644 KB Output is correct
64 Correct 167 ms 7644 KB Output is correct
65 Correct 182 ms 7644 KB Output is correct
66 Correct 166 ms 7644 KB Output is correct
67 Correct 131 ms 5728 KB Output is correct
68 Correct 138 ms 7644 KB Output is correct
69 Correct 137 ms 7792 KB Output is correct
70 Correct 145 ms 5728 KB Output is correct
71 Correct 357 ms 14888 KB Output is correct
72 Correct 352 ms 14932 KB Output is correct
73 Correct 362 ms 14932 KB Output is correct
74 Correct 356 ms 14928 KB Output is correct
75 Correct 355 ms 14932 KB Output is correct
76 Correct 336 ms 14936 KB Output is correct
77 Correct 336 ms 14932 KB Output is correct
78 Correct 338 ms 14932 KB Output is correct
79 Correct 343 ms 14932 KB Output is correct
80 Correct 335 ms 14964 KB Output is correct
81 Correct 1 ms 364 KB Output is correct
82 Correct 2 ms 364 KB Output is correct
83 Correct 2 ms 364 KB Output is correct
84 Correct 2 ms 364 KB Output is correct
85 Correct 3 ms 364 KB Output is correct
86 Correct 2 ms 364 KB Output is correct
87 Correct 206 ms 5728 KB Output is correct
88 Correct 200 ms 5728 KB Output is correct
89 Correct 200 ms 5600 KB Output is correct
90 Correct 196 ms 5728 KB Output is correct
91 Correct 197 ms 5600 KB Output is correct
92 Correct 213 ms 5600 KB Output is correct
93 Correct 208 ms 5728 KB Output is correct
94 Correct 212 ms 5600 KB Output is correct
95 Correct 207 ms 5600 KB Output is correct
96 Correct 210 ms 5600 KB Output is correct
97 Correct 140 ms 7708 KB Output is correct
98 Correct 137 ms 7644 KB Output is correct
99 Correct 136 ms 7644 KB Output is correct
100 Correct 141 ms 7772 KB Output is correct
101 Correct 134 ms 7644 KB Output is correct
102 Correct 136 ms 7772 KB Output is correct
103 Correct 139 ms 7644 KB Output is correct
104 Correct 136 ms 7772 KB Output is correct
105 Correct 140 ms 7772 KB Output is correct
106 Correct 159 ms 7708 KB Output is correct