#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmin(T& _old, T _new) { return _old > _new && (_old = _new, true); }
template <class T>
bool chmax(T& _old, T _new) { return _old < _new && (_old = _new, true); }
/* basics */
namespace geo {
#define EPS 1e-8
template <typename T, enable_if_t<is_integral<T>::value, bool> = true>
int sign(T x) { return (x > 0) - (x < 0); }
template <typename T, enable_if_t<is_floating_point<T>::value, bool> = true>
int sign(T x) { return (x > EPS) - (x < -EPS); }
}; // namespace geo
/* point2D */
namespace geo {
template <typename T>
struct point2D {
T x, y;
point2D() = default;
point2D(T _x, T _y) : x(_x), y(_y) {}
template <typename U>
explicit point2D(const point2D<U>& p) : x(p.x), y(p.y) {}
using P = point2D;
bool operator<(const P& p) const { return tie(x, y) < tie(p.x, p.y); }
bool operator==(const P& p) const { return tie(x, y) == tie(p.x, p.y); }
bool operator!=(const P& p) const { return tie(x, y) != tie(p.x, p.y); }
friend P operator+(const P& a, const P& b) { return P(a.x + b.x, a.y + b.y); }
friend P operator-(const P& a, const P& b) { return P(a.x - b.x, a.y - b.y); }
friend P operator*(const P& a, const T& scalar) { return P(a.x * scalar, a.y * scalar); }
friend P operator*(const T& scalar, const P& a) { return P(scalar * a.x, scalar * a.y); }
friend P operator/(const P& a, const T& scalar) { return P(a.x / scalar, a.y / scalar); }
friend ostream& operator<<(ostream& o, const P& p) { return o << '(' << p.x << ", " << p.y << ')'; }
friend istream& operator>>(istream& i, P& p) { return i >> p.x >> p.y; }
T dot(const P& p) const { return x * p.x + y * p.y; }
T cross(const P& p) const { return x * p.y - y * p.x; }
T cross(const P& a, const P& b) const { return (a - *this).cross(b - *this); }
T dist2() const { return x * x + y * y; }
double dist() const { return sqrt(dist2()); }
P perp_cw() const { return P(y, -x); }
P perp_ccw() const { return P(-y, x); }
P unit() const { return *this / dist(); }
P normal() const { return perp_ccw().unit(); }
P unit_int() const { return x || y ? *this / gcd(x, y) : *this; }
P normal_int() const { return perp_ccw().unit_int(); }
bool same_dir(const P& p) const { return cross(p) == 0 && dot(p) > 0; }
int side_of(const P& s, const P& e) const {
if constexpr (is_integral_v<T>) {
return sign(s.cross(e, *this));
} else {
auto res = (e - s).cross(*this - s);
double l = (e - s).dist() * EPS;
return (res > l) - (res < -l);
}
}
double angle() const { return atan2(y, x); }
P rotate(double radian) const {
return P(x * cos(radian) - y * sin(radian), x * sin(radian) + y * cos(radian));
}
};
}; // namespace geo
namespace geo {
template <typename T>
vector<point2D<T>> convex_hull(vector<point2D<T>> pts) {
if (pts.size() <= 1) return pts;
sort(pts.begin(), pts.end());
vector<point2D<T>> hull(pts.size() + 1);
int s = 0, t = 0;
for (int it = 2; it--; s = --t, reverse(pts.begin(), pts.end()))
for (const auto& p : pts) {
while (t >= s + 2 && hull[t - 2].cross(hull[t - 1], p) <= 0) t--;
hull[t++] = p;
}
return {hull.begin(), hull.begin() + t - (t == 2 && hull[0] == hull[1])};
}
}; // namespace geo
namespace geo::distance2 {
template <typename T>
T hull_diameter(const vector<point2D<T>>& hull) {
T diameter = 0;
int n = hull.size();
for (int i = 0, j = n > 1; i < j; ++i) {
for (;; j = j == n - 1 ? 0 : j + 1) {
chmax(diameter, (hull[i] - hull[j]).dist2());
if ((hull[(j + 1) % n] - hull[j]).cross(hull[i + 1] - hull[i]) >= 0)
break;
}
}
return diameter;
}
}; // namespace geo::distance2
struct star_t {
int x, y, dx, dy;
};
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
#ifdef palilo
freopen("in", "r", stdin);
freopen("out", "w", stdout);
#endif
int n, t;
cin >> n >> t;
vector<star_t> a(n);
for (auto& [x, y, dx, dy] : a) {
cin >> x >> y >> dx >> dy;
}
auto cross2 = [&](const pair<int, int>& u, const pair<int, int>& v) {
return int64_t(u.first) * v.second - int64_t(u.second) * v.first;
};
auto cross3 = [&](const pair<int, int>& o, const pair<int, int>& u, const pair<int, int>& v) {
return int64_t(u.first - o.first) * (v.second - o.second) -
int64_t(u.second - o.second) * (v.first - o.first);
};
auto dist = [&](const pair<int, int>& u, const pair<int, int>& v) {
int64_t dx = u.first - v.first, dy = u.second - v.second;
return dx * dx + dy * dy;
};
using point = geo::point2D<int64_t>;
vector<point> star(n);
auto f = [&](int dt) -> int64_t {
transform(a.begin(), a.end(), star.begin(), [&](const auto& star) {
return point(star.x + star.dx * dt, star.y + star.dy * dt);
});
auto hull = geo::convex_hull(star);
return geo::distance2::hull_diameter(hull);
};
int lo = 0, hi = t;
while (lo != hi) {
const auto ml = lo + (hi - lo) / 3;
const auto mr = hi - (hi - lo) / 3;
f(ml) <= f(mr) ? hi = mr - 1 : lo = ml + 1;
}
cout << lo << '\n';
cout << f(lo);
}
Compilation message
dist.cpp: In function 'int main()':
dist.cpp:125:10: warning: variable 'cross2' set but not used [-Wunused-but-set-variable]
125 | auto cross2 = [&](const pair<int, int>& u, const pair<int, int>& v) {
| ^~~~~~
dist.cpp:128:10: warning: variable 'cross3' set but not used [-Wunused-but-set-variable]
128 | auto cross3 = [&](const pair<int, int>& o, const pair<int, int>& u, const pair<int, int>& v) {
| ^~~~~~
dist.cpp:132:10: warning: variable 'dist' set but not used [-Wunused-but-set-variable]
132 | auto dist = [&](const pair<int, int>& u, const pair<int, int>& v) {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
8 ms |
332 KB |
Output is correct |
12 |
Correct |
7 ms |
328 KB |
Output is correct |
13 |
Correct |
6 ms |
332 KB |
Output is correct |
14 |
Correct |
7 ms |
332 KB |
Output is correct |
15 |
Correct |
5 ms |
332 KB |
Output is correct |
16 |
Correct |
6 ms |
332 KB |
Output is correct |
17 |
Correct |
4 ms |
332 KB |
Output is correct |
18 |
Correct |
3 ms |
332 KB |
Output is correct |
19 |
Correct |
5 ms |
332 KB |
Output is correct |
20 |
Correct |
7 ms |
404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
2204 KB |
Output is correct |
2 |
Correct |
55 ms |
2736 KB |
Output is correct |
3 |
Correct |
54 ms |
2728 KB |
Output is correct |
4 |
Correct |
58 ms |
3296 KB |
Output is correct |
5 |
Correct |
51 ms |
2892 KB |
Output is correct |
6 |
Correct |
61 ms |
3220 KB |
Output is correct |
7 |
Correct |
28 ms |
2636 KB |
Output is correct |
8 |
Correct |
29 ms |
2564 KB |
Output is correct |
9 |
Correct |
57 ms |
3248 KB |
Output is correct |
10 |
Correct |
57 ms |
2812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
8 ms |
332 KB |
Output is correct |
12 |
Correct |
7 ms |
328 KB |
Output is correct |
13 |
Correct |
6 ms |
332 KB |
Output is correct |
14 |
Correct |
7 ms |
332 KB |
Output is correct |
15 |
Correct |
5 ms |
332 KB |
Output is correct |
16 |
Correct |
6 ms |
332 KB |
Output is correct |
17 |
Correct |
4 ms |
332 KB |
Output is correct |
18 |
Correct |
3 ms |
332 KB |
Output is correct |
19 |
Correct |
5 ms |
332 KB |
Output is correct |
20 |
Correct |
7 ms |
404 KB |
Output is correct |
21 |
Correct |
56 ms |
2204 KB |
Output is correct |
22 |
Correct |
55 ms |
2736 KB |
Output is correct |
23 |
Correct |
54 ms |
2728 KB |
Output is correct |
24 |
Correct |
58 ms |
3296 KB |
Output is correct |
25 |
Correct |
51 ms |
2892 KB |
Output is correct |
26 |
Correct |
61 ms |
3220 KB |
Output is correct |
27 |
Correct |
28 ms |
2636 KB |
Output is correct |
28 |
Correct |
29 ms |
2564 KB |
Output is correct |
29 |
Correct |
57 ms |
3248 KB |
Output is correct |
30 |
Correct |
57 ms |
2812 KB |
Output is correct |
31 |
Correct |
284 ms |
2900 KB |
Output is correct |
32 |
Correct |
262 ms |
2864 KB |
Output is correct |
33 |
Correct |
268 ms |
2740 KB |
Output is correct |
34 |
Correct |
288 ms |
2872 KB |
Output is correct |
35 |
Correct |
231 ms |
2884 KB |
Output is correct |
36 |
Correct |
292 ms |
3220 KB |
Output is correct |
37 |
Correct |
120 ms |
2892 KB |
Output is correct |
38 |
Correct |
113 ms |
2892 KB |
Output is correct |
39 |
Correct |
189 ms |
2908 KB |
Output is correct |
40 |
Correct |
258 ms |
2844 KB |
Output is correct |
41 |
Correct |
279 ms |
3280 KB |
Output is correct |
42 |
Correct |
254 ms |
3348 KB |
Output is correct |