답안 #373765

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373765 2021-03-05T16:39:10 Z mode149256 Wish (LMIO19_noras) C++17
0 / 100
1 ms 364 KB
/*input
2 2
3 0 5 0
-2 1 2 1
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 = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
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);
}

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 = MOD;
		ll m;
		while (h - l > 4) {
			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 first = [&](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 last = [&](beam b, ll best_dis) -> ll {
		ll l = best_dis;
		ll h = MOD;
		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);
		if (dis(getnth(ind, b), og) > R * R) continue;

		ll from = first(b, ind);
		ll to = last(b, ind);
		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 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -