#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
struct Star{
ll x, y, dx, dy;
void get(){
cin >> x >> y >> dx >> dy;
}
};
int n, t;
vector<Star> v;
vector<p> arr;
int ccw(p a, p b, p c){
ll res = (a.first*b.second) + (b.first*c.second) + (c.first*a.second);
res -= (b.first*a.second) + (c.first*b.second) + (a.first*c.second);
if(res > 0) return 1;
if(res) return -1;
return 0;
}
ll dist(p a, p b){
ll dx = a.first - b.first;
ll dy = a.second - b.second;
return dx*dx + dy*dy;
}
bool chk(p s, p e, p ss, p ee){
return ccw({0, 0}, {e.first-s.first, e.second-s.second}, {ee.first-ss.first, ee.second-ss.second}) >= 0;
}
ll f(int t){
for(int i=0; i<n; i++){
arr[i] = {v[i].x + v[i].dx * t, v[i].y + v[i].dy * t};
}
swap(arr[0], *min_element(arr.begin(), arr.end()));
sort(arr.begin()+1, arr.end(), [](const p a, const p b){
int cw = ccw(arr[0], a, b);
if(cw) return cw > 0;
return dist(arr[0], a) < dist(arr[0], b);
});
vector<p> hull;
for(int i=0; i<n; i++){
while(hull.size() >= 2 && ccw(hull[hull.size()-2], hull.back(), arr[i]) <= 0){
hull.pop_back();
}
hull.push_back(arr[i]);
}
ll ret = 0;
int p = 0;
for(int i=0; i<hull.size(); i++){
while(p+1 < hull.size() && chk(hull[i], hull[i+1], hull[p], hull[p+1])){
ret = max(ret, dist(hull[i], hull[p])); p++;
}
ret = max(ret, dist(hull[i], hull[p]));
}
return ret;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> t;
v.resize(n); arr.resize(n);
for(int i=0; i<n; i++) v[i].get();
ll s = 0, e = t;
while(s+3 <= e){
ll l = (s+s+e)/3, r = (s+e+e)/3;
ll t1 = f(l), t2 = f(r);
if(t1 > t2) s = l;
else e = r;
}
ll ans = 1e18;
int idx = s;
for(ll i=s; i<=e; i++){
ll now = f(i);
if(ans > now){
ans = now, idx = i;
}
}
cout << idx << "\n" << ans;
}
Compilation message
dist.cpp: In function 'll f(int)':
dist.cpp:57:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<hull.size(); i++){
~^~~~~~~~~~~~
dist.cpp:58:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(p+1 < hull.size() && chk(hull[i], hull[i+1], hull[p], hull[p+1])){
~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
356 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
356 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
10 ms |
512 KB |
Output is correct |
12 |
Correct |
13 ms |
512 KB |
Output is correct |
13 |
Correct |
9 ms |
384 KB |
Output is correct |
14 |
Correct |
13 ms |
384 KB |
Output is correct |
15 |
Correct |
12 ms |
384 KB |
Output is correct |
16 |
Correct |
19 ms |
512 KB |
Output is correct |
17 |
Correct |
14 ms |
384 KB |
Output is correct |
18 |
Correct |
10 ms |
356 KB |
Output is correct |
19 |
Correct |
8 ms |
384 KB |
Output is correct |
20 |
Correct |
11 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
94 ms |
2636 KB |
Output is correct |
2 |
Correct |
96 ms |
2484 KB |
Output is correct |
3 |
Correct |
84 ms |
2304 KB |
Output is correct |
4 |
Correct |
83 ms |
3476 KB |
Output is correct |
5 |
Correct |
108 ms |
2488 KB |
Output is correct |
6 |
Correct |
143 ms |
3404 KB |
Output is correct |
7 |
Correct |
68 ms |
2296 KB |
Output is correct |
8 |
Correct |
47 ms |
2048 KB |
Output is correct |
9 |
Correct |
71 ms |
3536 KB |
Output is correct |
10 |
Correct |
81 ms |
2432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
356 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
10 ms |
512 KB |
Output is correct |
12 |
Correct |
13 ms |
512 KB |
Output is correct |
13 |
Correct |
9 ms |
384 KB |
Output is correct |
14 |
Correct |
13 ms |
384 KB |
Output is correct |
15 |
Correct |
12 ms |
384 KB |
Output is correct |
16 |
Correct |
19 ms |
512 KB |
Output is correct |
17 |
Correct |
14 ms |
384 KB |
Output is correct |
18 |
Correct |
10 ms |
356 KB |
Output is correct |
19 |
Correct |
8 ms |
384 KB |
Output is correct |
20 |
Correct |
11 ms |
384 KB |
Output is correct |
21 |
Correct |
94 ms |
2636 KB |
Output is correct |
22 |
Correct |
96 ms |
2484 KB |
Output is correct |
23 |
Correct |
84 ms |
2304 KB |
Output is correct |
24 |
Correct |
83 ms |
3476 KB |
Output is correct |
25 |
Correct |
108 ms |
2488 KB |
Output is correct |
26 |
Correct |
143 ms |
3404 KB |
Output is correct |
27 |
Correct |
68 ms |
2296 KB |
Output is correct |
28 |
Correct |
47 ms |
2048 KB |
Output is correct |
29 |
Correct |
71 ms |
3536 KB |
Output is correct |
30 |
Correct |
81 ms |
2432 KB |
Output is correct |
31 |
Correct |
364 ms |
2516 KB |
Output is correct |
32 |
Correct |
387 ms |
2424 KB |
Output is correct |
33 |
Correct |
381 ms |
2424 KB |
Output is correct |
34 |
Correct |
406 ms |
2680 KB |
Output is correct |
35 |
Correct |
452 ms |
2556 KB |
Output is correct |
36 |
Correct |
373 ms |
3460 KB |
Output is correct |
37 |
Correct |
362 ms |
2432 KB |
Output is correct |
38 |
Correct |
247 ms |
2680 KB |
Output is correct |
39 |
Correct |
297 ms |
2552 KB |
Output is correct |
40 |
Correct |
369 ms |
2552 KB |
Output is correct |
41 |
Correct |
405 ms |
3496 KB |
Output is correct |
42 |
Correct |
355 ms |
3648 KB |
Output is correct |