#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 && ccw(Star(0, 0), 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;
while(r - l >= 3) {
int m1 = (2 * l + r) / 3;
int m2 = (l + 2 * r) / 3;
if(solve(m1) > solve(m2)) l = m1;
else r = m2;
}
int date = 0;
long long res = LLONG_MAX;
for(int k = l; k <= r; k++) {
long long potential = solve(k);
if(res > potential) {
res = potential;
date = k;
}
}
cout << date << '\n' << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 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 |
3156 KB |
Output is correct |
7 |
Correct |
2 ms |
3028 KB |
Output is correct |
8 |
Correct |
2 ms |
3044 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 |
2 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 |
3156 KB |
Output is correct |
7 |
Correct |
2 ms |
3028 KB |
Output is correct |
8 |
Correct |
2 ms |
3044 KB |
Output is correct |
9 |
Correct |
1 ms |
3028 KB |
Output is correct |
10 |
Correct |
2 ms |
3028 KB |
Output is correct |
11 |
Correct |
9 ms |
3028 KB |
Output is correct |
12 |
Correct |
11 ms |
3140 KB |
Output is correct |
13 |
Correct |
8 ms |
3028 KB |
Output is correct |
14 |
Correct |
9 ms |
3028 KB |
Output is correct |
15 |
Correct |
11 ms |
3140 KB |
Output is correct |
16 |
Correct |
13 ms |
3144 KB |
Output is correct |
17 |
Correct |
9 ms |
3136 KB |
Output is correct |
18 |
Correct |
6 ms |
3028 KB |
Output is correct |
19 |
Correct |
7 ms |
3144 KB |
Output is correct |
20 |
Correct |
12 ms |
3028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
3120 KB |
Output is correct |
2 |
Correct |
70 ms |
3028 KB |
Output is correct |
3 |
Correct |
70 ms |
3116 KB |
Output is correct |
4 |
Correct |
61 ms |
3028 KB |
Output is correct |
5 |
Correct |
88 ms |
3124 KB |
Output is correct |
6 |
Correct |
88 ms |
3028 KB |
Output is correct |
7 |
Correct |
59 ms |
3028 KB |
Output is correct |
8 |
Correct |
46 ms |
3120 KB |
Output is correct |
9 |
Correct |
63 ms |
3028 KB |
Output is correct |
10 |
Correct |
93 ms |
3120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 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 |
3156 KB |
Output is correct |
7 |
Correct |
2 ms |
3028 KB |
Output is correct |
8 |
Correct |
2 ms |
3044 KB |
Output is correct |
9 |
Correct |
1 ms |
3028 KB |
Output is correct |
10 |
Correct |
2 ms |
3028 KB |
Output is correct |
11 |
Correct |
9 ms |
3028 KB |
Output is correct |
12 |
Correct |
11 ms |
3140 KB |
Output is correct |
13 |
Correct |
8 ms |
3028 KB |
Output is correct |
14 |
Correct |
9 ms |
3028 KB |
Output is correct |
15 |
Correct |
11 ms |
3140 KB |
Output is correct |
16 |
Correct |
13 ms |
3144 KB |
Output is correct |
17 |
Correct |
9 ms |
3136 KB |
Output is correct |
18 |
Correct |
6 ms |
3028 KB |
Output is correct |
19 |
Correct |
7 ms |
3144 KB |
Output is correct |
20 |
Correct |
12 ms |
3028 KB |
Output is correct |
21 |
Correct |
83 ms |
3120 KB |
Output is correct |
22 |
Correct |
70 ms |
3028 KB |
Output is correct |
23 |
Correct |
70 ms |
3116 KB |
Output is correct |
24 |
Correct |
61 ms |
3028 KB |
Output is correct |
25 |
Correct |
88 ms |
3124 KB |
Output is correct |
26 |
Correct |
88 ms |
3028 KB |
Output is correct |
27 |
Correct |
59 ms |
3028 KB |
Output is correct |
28 |
Correct |
46 ms |
3120 KB |
Output is correct |
29 |
Correct |
63 ms |
3028 KB |
Output is correct |
30 |
Correct |
93 ms |
3120 KB |
Output is correct |
31 |
Correct |
354 ms |
3120 KB |
Output is correct |
32 |
Correct |
333 ms |
3124 KB |
Output is correct |
33 |
Correct |
335 ms |
3124 KB |
Output is correct |
34 |
Correct |
326 ms |
3116 KB |
Output is correct |
35 |
Correct |
363 ms |
3116 KB |
Output is correct |
36 |
Correct |
294 ms |
3116 KB |
Output is correct |
37 |
Correct |
304 ms |
3120 KB |
Output is correct |
38 |
Correct |
181 ms |
3116 KB |
Output is correct |
39 |
Correct |
264 ms |
3128 KB |
Output is correct |
40 |
Correct |
350 ms |
3132 KB |
Output is correct |
41 |
Correct |
335 ms |
3124 KB |
Output is correct |
42 |
Correct |
359 ms |
3120 KB |
Output is correct |