답안 #373775

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373775 2021-03-05T17:52:47 Z mode149256 Wish (LMIO19_noras) C++17
100 / 100
224 ms 19436 KB
/*input
2 1
-3 -2 -1 -1
-2 2 -1 1
*/
#include <bits/stdc++.h>
using namespace std;

namespace my_template {
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;

#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"

const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;

template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }

template<typename T>
void print(vector<T> vec, string name = "") {
	cout << name;
	for (auto u : vec)
		cout << u << ' ';
	cout << '\n';
}
}
using namespace my_template;

const int MOD = 200000007;
const ll INF = 1e12;
const int MX = 100101;

struct beam {
	pl prad;
	pl dxy;
};

int N;
ll R;

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

pl getnth(ll n, pl a, pl dxy) {
	return {a.x + dxy.x * n, a.y + dxy.y * n};
}

pl getnth(ll n, beam b) {
	return getnth(n, b.prad, b.dxy);
}

ll getINF(beam b) {
	return (MOD) / max(abs(b.dxy.x), abs(b.dxy.y));
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> N >> R;
	pl og = {0, 0};

	vector<beam> sk(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}};
	}

	auto closest = [&](beam b) -> ll {
		ll l = 0;
		ll h = getINF(b);
		// printf("%lld %lld, %lld %lld, h = %lld\n", b.prad.x, b.prad.y, b.dxy.x, b.dxy.y, h);
		ll m;
		while (h - l > 6) {
			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;
			}
		}

		pl ret = getnth(l, b);
		ll n = l;
		ll c = dis(ret, og);
		for (ll i = l + 1; i <= h; ++i)
		{
			pl nl = getnth(i, b);
			ll nc = dis(nl, og);
			if (nc < c) {
				c = nc;
				ret = nl;
				n = i;
			}
		}
		return n;
	};

	auto pirmas = [&](beam b, ll best_dis) -> ll {
		ll l = 0;
		ll h = best_dis;
		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;
	};

	auto pask = [&](beam b, ll best_dis) -> ll {
		ll l = best_dis;
		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;
	};

	vector<pl> kas;

	for (auto b : sk) {
		ll ind = closest(b);
		// printf("%lld %lld, ind = %lld\n", b.prad.x, b.prad.y, ind);
		if (dis(getnth(ind, b), og) > R * R) continue;

		ll from = pirmas(b, ind);
		ll to = pask(b, ind);
		// printf("%lld %lld, %lld %lld, from = %lld, to = %lld\n", b.prad.x, b.prad.y, b.dxy.x, b.dxy.y, from, to);
		assert(from <= to);
		kas.emplace_back(from, 1);
		kas.emplace_back(to + 1, -1);
	}
	sort(kas.begin(), kas.end());
	ll ats = 0;
	ll curr = 0;

	int j = 0;
	while (j < (int)kas.size()) {
		ll dabar = kas[j].x;
		while (j < (int)kas.size() and kas[j].x == dabar) {
			curr += kas[j].y;
			j++;
		}
		ats = max(ats, curr);
	}

	printf("%lld\n", ats);
}

/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* array bounds
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 58 ms 9316 KB Output is correct
24 Correct 58 ms 9316 KB Output is correct
25 Correct 61 ms 9316 KB Output is correct
26 Correct 60 ms 9348 KB Output is correct
27 Correct 62 ms 7656 KB Output is correct
28 Correct 64 ms 9444 KB Output is correct
29 Correct 70 ms 9444 KB Output is correct
30 Correct 64 ms 9444 KB Output is correct
31 Correct 64 ms 9444 KB Output is correct
32 Correct 124 ms 9444 KB Output is correct
33 Correct 89 ms 9444 KB Output is correct
34 Correct 100 ms 9444 KB Output is correct
35 Correct 90 ms 9572 KB Output is correct
36 Correct 90 ms 9444 KB Output is correct
37 Correct 69 ms 7272 KB Output is correct
38 Correct 66 ms 7232 KB Output is correct
39 Correct 63 ms 7272 KB Output is correct
40 Correct 65 ms 7272 KB Output is correct
41 Correct 63 ms 7272 KB Output is correct
42 Correct 66 ms 7440 KB Output is correct
43 Correct 198 ms 19164 KB Output is correct
44 Correct 199 ms 19164 KB Output is correct
45 Correct 218 ms 19164 KB Output is correct
46 Correct 217 ms 19168 KB Output is correct
47 Correct 208 ms 19184 KB Output is correct
48 Correct 182 ms 18528 KB Output is correct
49 Correct 220 ms 18396 KB Output is correct
50 Correct 179 ms 18400 KB Output is correct
51 Correct 179 ms 18432 KB Output is correct
52 Correct 180 ms 18396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 58 ms 9316 KB Output is correct
24 Correct 58 ms 9316 KB Output is correct
25 Correct 61 ms 9316 KB Output is correct
26 Correct 60 ms 9348 KB Output is correct
27 Correct 62 ms 7656 KB Output is correct
28 Correct 64 ms 9444 KB Output is correct
29 Correct 70 ms 9444 KB Output is correct
30 Correct 64 ms 9444 KB Output is correct
31 Correct 64 ms 9444 KB Output is correct
32 Correct 124 ms 9444 KB Output is correct
33 Correct 89 ms 9444 KB Output is correct
34 Correct 100 ms 9444 KB Output is correct
35 Correct 90 ms 9572 KB Output is correct
36 Correct 90 ms 9444 KB Output is correct
37 Correct 69 ms 7272 KB Output is correct
38 Correct 66 ms 7232 KB Output is correct
39 Correct 63 ms 7272 KB Output is correct
40 Correct 65 ms 7272 KB Output is correct
41 Correct 63 ms 7272 KB Output is correct
42 Correct 66 ms 7440 KB Output is correct
43 Correct 198 ms 19164 KB Output is correct
44 Correct 199 ms 19164 KB Output is correct
45 Correct 218 ms 19164 KB Output is correct
46 Correct 217 ms 19168 KB Output is correct
47 Correct 208 ms 19184 KB Output is correct
48 Correct 182 ms 18528 KB Output is correct
49 Correct 220 ms 18396 KB Output is correct
50 Correct 179 ms 18400 KB Output is correct
51 Correct 179 ms 18432 KB Output is correct
52 Correct 180 ms 18396 KB Output is correct
53 Correct 1 ms 364 KB Output is correct
54 Correct 1 ms 492 KB Output is correct
55 Correct 2 ms 492 KB Output is correct
56 Correct 1 ms 492 KB Output is correct
57 Correct 1 ms 492 KB Output is correct
58 Correct 1 ms 492 KB Output is correct
59 Correct 60 ms 9316 KB Output is correct
60 Correct 62 ms 7656 KB Output is correct
61 Correct 66 ms 7656 KB Output is correct
62 Correct 73 ms 7656 KB Output is correct
63 Correct 76 ms 7656 KB Output is correct
64 Correct 76 ms 7656 KB Output is correct
65 Correct 78 ms 7784 KB Output is correct
66 Correct 78 ms 7784 KB Output is correct
67 Correct 79 ms 7784 KB Output is correct
68 Correct 113 ms 9572 KB Output is correct
69 Correct 93 ms 9572 KB Output is correct
70 Correct 90 ms 9572 KB Output is correct
71 Correct 93 ms 9760 KB Output is correct
72 Correct 92 ms 9700 KB Output is correct
73 Correct 65 ms 7144 KB Output is correct
74 Correct 67 ms 9316 KB Output is correct
75 Correct 68 ms 9316 KB Output is correct
76 Correct 74 ms 7304 KB Output is correct
77 Correct 213 ms 19436 KB Output is correct
78 Correct 188 ms 19312 KB Output is correct
79 Correct 194 ms 19424 KB Output is correct
80 Correct 224 ms 19292 KB Output is correct
81 Correct 208 ms 19168 KB Output is correct
82 Correct 186 ms 18780 KB Output is correct
83 Correct 185 ms 18792 KB Output is correct
84 Correct 182 ms 18784 KB Output is correct
85 Correct 194 ms 18780 KB Output is correct
86 Correct 183 ms 18780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 58 ms 9316 KB Output is correct
24 Correct 58 ms 9316 KB Output is correct
25 Correct 61 ms 9316 KB Output is correct
26 Correct 60 ms 9348 KB Output is correct
27 Correct 62 ms 7656 KB Output is correct
28 Correct 64 ms 9444 KB Output is correct
29 Correct 70 ms 9444 KB Output is correct
30 Correct 64 ms 9444 KB Output is correct
31 Correct 64 ms 9444 KB Output is correct
32 Correct 124 ms 9444 KB Output is correct
33 Correct 89 ms 9444 KB Output is correct
34 Correct 100 ms 9444 KB Output is correct
35 Correct 90 ms 9572 KB Output is correct
36 Correct 90 ms 9444 KB Output is correct
37 Correct 69 ms 7272 KB Output is correct
38 Correct 66 ms 7232 KB Output is correct
39 Correct 63 ms 7272 KB Output is correct
40 Correct 65 ms 7272 KB Output is correct
41 Correct 63 ms 7272 KB Output is correct
42 Correct 66 ms 7440 KB Output is correct
43 Correct 198 ms 19164 KB Output is correct
44 Correct 199 ms 19164 KB Output is correct
45 Correct 218 ms 19164 KB Output is correct
46 Correct 217 ms 19168 KB Output is correct
47 Correct 208 ms 19184 KB Output is correct
48 Correct 182 ms 18528 KB Output is correct
49 Correct 220 ms 18396 KB Output is correct
50 Correct 179 ms 18400 KB Output is correct
51 Correct 179 ms 18432 KB Output is correct
52 Correct 180 ms 18396 KB Output is correct
53 Correct 60 ms 9316 KB Output is correct
54 Correct 62 ms 7656 KB Output is correct
55 Correct 66 ms 7656 KB Output is correct
56 Correct 73 ms 7656 KB Output is correct
57 Correct 76 ms 7656 KB Output is correct
58 Correct 76 ms 7656 KB Output is correct
59 Correct 78 ms 7784 KB Output is correct
60 Correct 78 ms 7784 KB Output is correct
61 Correct 79 ms 7784 KB Output is correct
62 Correct 113 ms 9572 KB Output is correct
63 Correct 93 ms 9572 KB Output is correct
64 Correct 90 ms 9572 KB Output is correct
65 Correct 93 ms 9760 KB Output is correct
66 Correct 92 ms 9700 KB Output is correct
67 Correct 65 ms 7144 KB Output is correct
68 Correct 67 ms 9316 KB Output is correct
69 Correct 68 ms 9316 KB Output is correct
70 Correct 74 ms 7304 KB Output is correct
71 Correct 213 ms 19436 KB Output is correct
72 Correct 188 ms 19312 KB Output is correct
73 Correct 194 ms 19424 KB Output is correct
74 Correct 224 ms 19292 KB Output is correct
75 Correct 208 ms 19168 KB Output is correct
76 Correct 186 ms 18780 KB Output is correct
77 Correct 185 ms 18792 KB Output is correct
78 Correct 182 ms 18784 KB Output is correct
79 Correct 194 ms 18780 KB Output is correct
80 Correct 183 ms 18780 KB Output is correct
81 Correct 1 ms 364 KB Output is correct
82 Correct 1 ms 492 KB Output is correct
83 Correct 2 ms 492 KB Output is correct
84 Correct 1 ms 492 KB Output is correct
85 Correct 1 ms 492 KB Output is correct
86 Correct 1 ms 492 KB Output is correct
87 Correct 86 ms 9320 KB Output is correct
88 Correct 87 ms 9320 KB Output is correct
89 Correct 84 ms 9320 KB Output is correct
90 Correct 80 ms 9320 KB Output is correct
91 Correct 111 ms 9320 KB Output is correct
92 Correct 91 ms 9192 KB Output is correct
93 Correct 91 ms 9352 KB Output is correct
94 Correct 92 ms 9320 KB Output is correct
95 Correct 91 ms 9320 KB Output is correct
96 Correct 91 ms 9320 KB Output is correct
97 Correct 51 ms 10084 KB Output is correct
98 Correct 52 ms 10084 KB Output is correct
99 Correct 52 ms 10212 KB Output is correct
100 Correct 56 ms 10084 KB Output is correct
101 Correct 50 ms 10084 KB Output is correct
102 Correct 51 ms 10084 KB Output is correct
103 Correct 55 ms 10124 KB Output is correct
104 Correct 52 ms 10212 KB Output is correct
105 Correct 53 ms 10084 KB Output is correct
106 Correct 58 ms 10084 KB Output is correct