#include <iostream>
#include <cstdlib>
#include <climits>
#include <algorithm>
using namespace std;
const int MAXN = 3e4 + 7;
struct Star {
long long x, y, dx, dy;
Star(long long x=0, long long y=0, long long dx=0, long long dy=0)
: x(x), y(y), dx(dx), dy(dy) {}
Star operator-(const Star &other) const {
return Star(x - other.x, y - other.y);
}
long long operator%(const Star &other) const {
return x * other.y - y * other.x;
}
};
int n, t, hull_size;
Star a[MAXN], p[MAXN];
Star convex_hull[MAXN];
int ccw(const Star &A, const Star &B, const Star &C) {
long long res = A % B + B % C + C % A;
return (res > 0) - (res < 0);
}
long long get_distance(const Star &A, const Star &B) {
long long dx = A.x - B.x;
long long dy = A.y - B.y;
return dx * dx + dy * dy;
}
long long solve(int k) {
for(int i = 1; i <= n; i++) {
p[i] = Star(a[i].x + k * a[i].dx, a[i].y + k * a[i].dy);
}
swap(p[1], *min_element(p + 1, p + n + 1, [](const Star &A, const Star &B) {
return A.x < B.x || (A.x == B.x && A.y < B.y);
}));
sort(p + 2, p + n + 1, [](const Star &A, const Star &B) {
int not_linear = ccw(p[1], A, B);
if(not_linear) return not_linear > 0;
return get_distance(p[1], A) < get_distance(p[1], B);
});
hull_size = 0;
for(int i = 1; i <= n; i++) {
while(hull_size >= 2 && ccw(convex_hull[hull_size - 1], convex_hull[hull_size], p[i]) <= 0){
hull_size--;
}
convex_hull[++hull_size] = p[i];
}
long long res = 0;
for(int i = 1, j = 1; i <= hull_size; i++) {
while(j < hull_size && (convex_hull[i + 1] - convex_hull[i]) % (convex_hull[j + 1] - convex_hull[j]) >= 0) {
res = max(res, get_distance(convex_hull[i], convex_hull[j]));
j++;
}
res = max(res, get_distance(convex_hull[i], convex_hull[j]));
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> t;
for(int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y >> a[i].dx >> a[i].dy;
int l = 0, r = t - 1;
while(l <= r) {
int m = (l + r) / 2;
if(solve(m) > solve(m + 1)) l = m + 1;
else r = m - 1;
}
cout << l << '\n' << solve(l);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3028 KB |
Output is correct |
2 |
Correct |
2 ms |
3028 KB |
Output is correct |
3 |
Correct |
1 ms |
3028 KB |
Output is correct |
4 |
Correct |
2 ms |
3028 KB |
Output is correct |
5 |
Correct |
2 ms |
3028 KB |
Output is correct |
6 |
Correct |
2 ms |
3028 KB |
Output is correct |
7 |
Correct |
2 ms |
3028 KB |
Output is correct |
8 |
Correct |
2 ms |
3088 KB |
Output is correct |
9 |
Correct |
1 ms |
3028 KB |
Output is correct |
10 |
Correct |
2 ms |
3028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3028 KB |
Output is correct |
2 |
Correct |
2 ms |
3028 KB |
Output is correct |
3 |
Correct |
1 ms |
3028 KB |
Output is correct |
4 |
Correct |
2 ms |
3028 KB |
Output is correct |
5 |
Correct |
2 ms |
3028 KB |
Output is correct |
6 |
Correct |
2 ms |
3028 KB |
Output is correct |
7 |
Correct |
2 ms |
3028 KB |
Output is correct |
8 |
Correct |
2 ms |
3088 KB |
Output is correct |
9 |
Correct |
1 ms |
3028 KB |
Output is correct |
10 |
Correct |
2 ms |
3028 KB |
Output is correct |
11 |
Correct |
6 ms |
3028 KB |
Output is correct |
12 |
Correct |
6 ms |
3028 KB |
Output is correct |
13 |
Correct |
5 ms |
3028 KB |
Output is correct |
14 |
Correct |
6 ms |
3028 KB |
Output is correct |
15 |
Correct |
6 ms |
3028 KB |
Output is correct |
16 |
Correct |
8 ms |
3028 KB |
Output is correct |
17 |
Correct |
7 ms |
3156 KB |
Output is correct |
18 |
Correct |
5 ms |
3028 KB |
Output is correct |
19 |
Correct |
5 ms |
3140 KB |
Output is correct |
20 |
Correct |
7 ms |
3028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
3116 KB |
Output is correct |
2 |
Correct |
58 ms |
3128 KB |
Output is correct |
3 |
Correct |
53 ms |
3120 KB |
Output is correct |
4 |
Correct |
44 ms |
3124 KB |
Output is correct |
5 |
Correct |
54 ms |
3028 KB |
Output is correct |
6 |
Correct |
67 ms |
3136 KB |
Output is correct |
7 |
Correct |
44 ms |
3116 KB |
Output is correct |
8 |
Correct |
28 ms |
3028 KB |
Output is correct |
9 |
Correct |
54 ms |
3028 KB |
Output is correct |
10 |
Correct |
55 ms |
3028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3028 KB |
Output is correct |
2 |
Correct |
2 ms |
3028 KB |
Output is correct |
3 |
Correct |
1 ms |
3028 KB |
Output is correct |
4 |
Correct |
2 ms |
3028 KB |
Output is correct |
5 |
Correct |
2 ms |
3028 KB |
Output is correct |
6 |
Correct |
2 ms |
3028 KB |
Output is correct |
7 |
Correct |
2 ms |
3028 KB |
Output is correct |
8 |
Correct |
2 ms |
3088 KB |
Output is correct |
9 |
Correct |
1 ms |
3028 KB |
Output is correct |
10 |
Correct |
2 ms |
3028 KB |
Output is correct |
11 |
Correct |
6 ms |
3028 KB |
Output is correct |
12 |
Correct |
6 ms |
3028 KB |
Output is correct |
13 |
Correct |
5 ms |
3028 KB |
Output is correct |
14 |
Correct |
6 ms |
3028 KB |
Output is correct |
15 |
Correct |
6 ms |
3028 KB |
Output is correct |
16 |
Correct |
8 ms |
3028 KB |
Output is correct |
17 |
Correct |
7 ms |
3156 KB |
Output is correct |
18 |
Correct |
5 ms |
3028 KB |
Output is correct |
19 |
Correct |
5 ms |
3140 KB |
Output is correct |
20 |
Correct |
7 ms |
3028 KB |
Output is correct |
21 |
Correct |
58 ms |
3116 KB |
Output is correct |
22 |
Correct |
58 ms |
3128 KB |
Output is correct |
23 |
Correct |
53 ms |
3120 KB |
Output is correct |
24 |
Correct |
44 ms |
3124 KB |
Output is correct |
25 |
Correct |
54 ms |
3028 KB |
Output is correct |
26 |
Correct |
67 ms |
3136 KB |
Output is correct |
27 |
Correct |
44 ms |
3116 KB |
Output is correct |
28 |
Correct |
28 ms |
3028 KB |
Output is correct |
29 |
Correct |
54 ms |
3028 KB |
Output is correct |
30 |
Correct |
55 ms |
3028 KB |
Output is correct |
31 |
Correct |
207 ms |
3028 KB |
Output is correct |
32 |
Correct |
229 ms |
3028 KB |
Output is correct |
33 |
Correct |
197 ms |
3148 KB |
Output is correct |
34 |
Correct |
199 ms |
3028 KB |
Output is correct |
35 |
Correct |
220 ms |
3116 KB |
Output is correct |
36 |
Correct |
168 ms |
3132 KB |
Output is correct |
37 |
Correct |
172 ms |
3028 KB |
Output is correct |
38 |
Correct |
113 ms |
3124 KB |
Output is correct |
39 |
Correct |
162 ms |
3028 KB |
Output is correct |
40 |
Correct |
210 ms |
3120 KB |
Output is correct |
41 |
Correct |
183 ms |
3028 KB |
Output is correct |
42 |
Correct |
211 ms |
3124 KB |
Output is correct |