답안 #375609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
375609 2021-03-09T15:18:29 Z mode149256 Wish (LMIO19_noras) C++17
100 / 100
203 ms 15120 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 492 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 2 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 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 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 1 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 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 2 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 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 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 1 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 57 ms 7652 KB Output is correct
24 Correct 59 ms 7740 KB Output is correct
25 Correct 61 ms 7652 KB Output is correct
26 Correct 61 ms 7652 KB Output is correct
27 Correct 57 ms 5608 KB Output is correct
28 Correct 62 ms 7652 KB Output is correct
29 Correct 63 ms 7652 KB Output is correct
30 Correct 65 ms 7652 KB Output is correct
31 Correct 71 ms 7780 KB Output is correct
32 Correct 91 ms 7800 KB Output is correct
33 Correct 88 ms 7780 KB Output is correct
34 Correct 91 ms 7652 KB Output is correct
35 Correct 90 ms 7652 KB Output is correct
36 Correct 103 ms 7780 KB Output is correct
37 Correct 67 ms 5608 KB Output is correct
38 Correct 65 ms 5608 KB Output is correct
39 Correct 62 ms 5608 KB Output is correct
40 Correct 66 ms 5736 KB Output is correct
41 Correct 63 ms 5608 KB Output is correct
42 Correct 65 ms 5736 KB Output is correct
43 Correct 203 ms 14940 KB Output is correct
44 Correct 200 ms 15092 KB Output is correct
45 Correct 200 ms 14940 KB Output is correct
46 Correct 199 ms 14944 KB Output is correct
47 Correct 201 ms 14992 KB Output is correct
48 Correct 193 ms 14960 KB Output is correct
49 Correct 186 ms 14920 KB Output is correct
50 Correct 186 ms 14944 KB Output is correct
51 Correct 194 ms 15120 KB Output is correct
52 Correct 190 ms 14944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 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 2 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 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 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 1 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 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 2 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 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 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 1 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 57 ms 7652 KB Output is correct
24 Correct 59 ms 7740 KB Output is correct
25 Correct 61 ms 7652 KB Output is correct
26 Correct 61 ms 7652 KB Output is correct
27 Correct 57 ms 5608 KB Output is correct
28 Correct 62 ms 7652 KB Output is correct
29 Correct 63 ms 7652 KB Output is correct
30 Correct 65 ms 7652 KB Output is correct
31 Correct 71 ms 7780 KB Output is correct
32 Correct 91 ms 7800 KB Output is correct
33 Correct 88 ms 7780 KB Output is correct
34 Correct 91 ms 7652 KB Output is correct
35 Correct 90 ms 7652 KB Output is correct
36 Correct 103 ms 7780 KB Output is correct
37 Correct 67 ms 5608 KB Output is correct
38 Correct 65 ms 5608 KB Output is correct
39 Correct 62 ms 5608 KB Output is correct
40 Correct 66 ms 5736 KB Output is correct
41 Correct 63 ms 5608 KB Output is correct
42 Correct 65 ms 5736 KB Output is correct
43 Correct 203 ms 14940 KB Output is correct
44 Correct 200 ms 15092 KB Output is correct
45 Correct 200 ms 14940 KB Output is correct
46 Correct 199 ms 14944 KB Output is correct
47 Correct 201 ms 14992 KB Output is correct
48 Correct 193 ms 14960 KB Output is correct
49 Correct 186 ms 14920 KB Output is correct
50 Correct 186 ms 14944 KB Output is correct
51 Correct 194 ms 15120 KB Output is correct
52 Correct 190 ms 14944 KB Output is correct
53 Correct 1 ms 364 KB Output is correct
54 Correct 1 ms 492 KB Output is correct
55 Correct 1 ms 492 KB Output is correct
56 Correct 1 ms 364 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 58 ms 7652 KB Output is correct
60 Correct 59 ms 5608 KB Output is correct
61 Correct 58 ms 5608 KB Output is correct
62 Correct 58 ms 5608 KB Output is correct
63 Correct 82 ms 5736 KB Output is correct
64 Correct 73 ms 5608 KB Output is correct
65 Correct 75 ms 5736 KB Output is correct
66 Correct 75 ms 5608 KB Output is correct
67 Correct 75 ms 5736 KB Output is correct
68 Correct 91 ms 7652 KB Output is correct
69 Correct 92 ms 7652 KB Output is correct
70 Correct 90 ms 7652 KB Output is correct
71 Correct 90 ms 7652 KB Output is correct
72 Correct 90 ms 7652 KB Output is correct
73 Correct 63 ms 5608 KB Output is correct
74 Correct 68 ms 7652 KB Output is correct
75 Correct 68 ms 7652 KB Output is correct
76 Correct 68 ms 5608 KB Output is correct
77 Correct 194 ms 15072 KB Output is correct
78 Correct 189 ms 14940 KB Output is correct
79 Correct 190 ms 15072 KB Output is correct
80 Correct 187 ms 14940 KB Output is correct
81 Correct 187 ms 14940 KB Output is correct
82 Correct 185 ms 15068 KB Output is correct
83 Correct 181 ms 14940 KB Output is correct
84 Correct 182 ms 14944 KB Output is correct
85 Correct 182 ms 15100 KB Output is correct
86 Correct 181 ms 14944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 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 2 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 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 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 1 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 57 ms 7652 KB Output is correct
24 Correct 59 ms 7740 KB Output is correct
25 Correct 61 ms 7652 KB Output is correct
26 Correct 61 ms 7652 KB Output is correct
27 Correct 57 ms 5608 KB Output is correct
28 Correct 62 ms 7652 KB Output is correct
29 Correct 63 ms 7652 KB Output is correct
30 Correct 65 ms 7652 KB Output is correct
31 Correct 71 ms 7780 KB Output is correct
32 Correct 91 ms 7800 KB Output is correct
33 Correct 88 ms 7780 KB Output is correct
34 Correct 91 ms 7652 KB Output is correct
35 Correct 90 ms 7652 KB Output is correct
36 Correct 103 ms 7780 KB Output is correct
37 Correct 67 ms 5608 KB Output is correct
38 Correct 65 ms 5608 KB Output is correct
39 Correct 62 ms 5608 KB Output is correct
40 Correct 66 ms 5736 KB Output is correct
41 Correct 63 ms 5608 KB Output is correct
42 Correct 65 ms 5736 KB Output is correct
43 Correct 203 ms 14940 KB Output is correct
44 Correct 200 ms 15092 KB Output is correct
45 Correct 200 ms 14940 KB Output is correct
46 Correct 199 ms 14944 KB Output is correct
47 Correct 201 ms 14992 KB Output is correct
48 Correct 193 ms 14960 KB Output is correct
49 Correct 186 ms 14920 KB Output is correct
50 Correct 186 ms 14944 KB Output is correct
51 Correct 194 ms 15120 KB Output is correct
52 Correct 190 ms 14944 KB Output is correct
53 Correct 58 ms 7652 KB Output is correct
54 Correct 59 ms 5608 KB Output is correct
55 Correct 58 ms 5608 KB Output is correct
56 Correct 58 ms 5608 KB Output is correct
57 Correct 82 ms 5736 KB Output is correct
58 Correct 73 ms 5608 KB Output is correct
59 Correct 75 ms 5736 KB Output is correct
60 Correct 75 ms 5608 KB Output is correct
61 Correct 75 ms 5736 KB Output is correct
62 Correct 91 ms 7652 KB Output is correct
63 Correct 92 ms 7652 KB Output is correct
64 Correct 90 ms 7652 KB Output is correct
65 Correct 90 ms 7652 KB Output is correct
66 Correct 90 ms 7652 KB Output is correct
67 Correct 63 ms 5608 KB Output is correct
68 Correct 68 ms 7652 KB Output is correct
69 Correct 68 ms 7652 KB Output is correct
70 Correct 68 ms 5608 KB Output is correct
71 Correct 194 ms 15072 KB Output is correct
72 Correct 189 ms 14940 KB Output is correct
73 Correct 190 ms 15072 KB Output is correct
74 Correct 187 ms 14940 KB Output is correct
75 Correct 187 ms 14940 KB Output is correct
76 Correct 185 ms 15068 KB Output is correct
77 Correct 181 ms 14940 KB Output is correct
78 Correct 182 ms 14944 KB Output is correct
79 Correct 182 ms 15100 KB Output is correct
80 Correct 181 ms 14944 KB Output is correct
81 Correct 1 ms 364 KB Output is correct
82 Correct 1 ms 492 KB Output is correct
83 Correct 1 ms 492 KB Output is correct
84 Correct 1 ms 364 KB Output is correct
85 Correct 1 ms 364 KB Output is correct
86 Correct 1 ms 364 KB Output is correct
87 Correct 85 ms 5608 KB Output is correct
88 Correct 85 ms 9320 KB Output is correct
89 Correct 83 ms 9320 KB Output is correct
90 Correct 80 ms 9320 KB Output is correct
91 Correct 79 ms 9320 KB Output is correct
92 Correct 91 ms 9192 KB Output is correct
93 Correct 92 ms 9320 KB Output is correct
94 Correct 92 ms 9448 KB Output is correct
95 Correct 92 ms 9320 KB Output is correct
96 Correct 94 ms 9448 KB Output is correct
97 Correct 56 ms 10084 KB Output is correct
98 Correct 53 ms 10084 KB Output is correct
99 Correct 52 ms 10084 KB Output is correct
100 Correct 52 ms 10084 KB Output is correct
101 Correct 53 ms 10084 KB Output is correct
102 Correct 54 ms 10084 KB Output is correct
103 Correct 55 ms 10084 KB Output is correct
104 Correct 52 ms 10084 KB Output is correct
105 Correct 54 ms 10084 KB Output is correct
106 Correct 53 ms 10084 KB Output is correct