# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
154820 |
2019-09-25T01:44:53 Z |
aer0park |
None (KOI16_dist) |
C++14 |
|
419 ms |
3484 KB |
#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){
p t = {e.first - s.first, e.second - s.second};
p tt = {ee.first - ss.first, ee.second - ss.second};
return ccw({0, 0}, t, tt) >= 0;
}
ll f(ll t){ //ternary search
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(), [](p a, p b){
int cw = ccw(arr[0], a, b);
if(cw) return cw > 0;
return dist(arr[0], a) < dist(arr[0], b);
});
//get convx hull
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]);
}
//rotating calipers
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();
//ternary search
ll s = 0, e = t;
while(s+3 <= e){
ll l = (s+s+e)/3, r = (s+e+e)/3;
if(f(l) > f(r)) 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(ll)':
dist.cpp:62:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<hull.size(); i++){
~^~~~~~~~~~~~
dist.cpp:63: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])){
~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
11 ms |
376 KB |
Output is correct |
12 |
Correct |
12 ms |
504 KB |
Output is correct |
13 |
Correct |
9 ms |
376 KB |
Output is correct |
14 |
Correct |
11 ms |
376 KB |
Output is correct |
15 |
Correct |
12 ms |
376 KB |
Output is correct |
16 |
Correct |
17 ms |
376 KB |
Output is correct |
17 |
Correct |
11 ms |
380 KB |
Output is correct |
18 |
Correct |
7 ms |
376 KB |
Output is correct |
19 |
Correct |
9 ms |
376 KB |
Output is correct |
20 |
Correct |
12 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
1784 KB |
Output is correct |
2 |
Correct |
85 ms |
2424 KB |
Output is correct |
3 |
Correct |
85 ms |
2428 KB |
Output is correct |
4 |
Correct |
80 ms |
3460 KB |
Output is correct |
5 |
Correct |
101 ms |
2552 KB |
Output is correct |
6 |
Correct |
112 ms |
3376 KB |
Output is correct |
7 |
Correct |
72 ms |
2168 KB |
Output is correct |
8 |
Correct |
54 ms |
2168 KB |
Output is correct |
9 |
Correct |
79 ms |
3484 KB |
Output is correct |
10 |
Correct |
95 ms |
2424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
11 ms |
376 KB |
Output is correct |
12 |
Correct |
12 ms |
504 KB |
Output is correct |
13 |
Correct |
9 ms |
376 KB |
Output is correct |
14 |
Correct |
11 ms |
376 KB |
Output is correct |
15 |
Correct |
12 ms |
376 KB |
Output is correct |
16 |
Correct |
17 ms |
376 KB |
Output is correct |
17 |
Correct |
11 ms |
380 KB |
Output is correct |
18 |
Correct |
7 ms |
376 KB |
Output is correct |
19 |
Correct |
9 ms |
376 KB |
Output is correct |
20 |
Correct |
12 ms |
376 KB |
Output is correct |
21 |
Correct |
95 ms |
1784 KB |
Output is correct |
22 |
Correct |
85 ms |
2424 KB |
Output is correct |
23 |
Correct |
85 ms |
2428 KB |
Output is correct |
24 |
Correct |
80 ms |
3460 KB |
Output is correct |
25 |
Correct |
101 ms |
2552 KB |
Output is correct |
26 |
Correct |
112 ms |
3376 KB |
Output is correct |
27 |
Correct |
72 ms |
2168 KB |
Output is correct |
28 |
Correct |
54 ms |
2168 KB |
Output is correct |
29 |
Correct |
79 ms |
3484 KB |
Output is correct |
30 |
Correct |
95 ms |
2424 KB |
Output is correct |
31 |
Correct |
396 ms |
2504 KB |
Output is correct |
32 |
Correct |
387 ms |
2336 KB |
Output is correct |
33 |
Correct |
388 ms |
2352 KB |
Output is correct |
34 |
Correct |
370 ms |
2552 KB |
Output is correct |
35 |
Correct |
419 ms |
2488 KB |
Output is correct |
36 |
Correct |
388 ms |
3476 KB |
Output is correct |
37 |
Correct |
350 ms |
2424 KB |
Output is correct |
38 |
Correct |
222 ms |
2424 KB |
Output is correct |
39 |
Correct |
295 ms |
2508 KB |
Output is correct |
40 |
Correct |
401 ms |
2552 KB |
Output is correct |
41 |
Correct |
413 ms |
3472 KB |
Output is correct |
42 |
Correct |
395 ms |
3420 KB |
Output is correct |