Submission #544642

# Submission time Handle Problem Language Result Execution time Memory
544642 2022-04-02T14:10:46 Z pokmui9909 None (KOI16_dist) C++17
100 / 100
581 ms 4320 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lf = long double;
 
#define x first
#define y second
using Point = pair<ll, ll>;
Point operator+ (Point p, Point q) {return Point(p.x + q.x, p.y + q.y);}
Point operator- (Point p, Point q) {return Point(p.x - q.x, p.y - q.y);}
ll    operator* (Point p, Point q) {return p.x * q.x + p.y * q.y;}
ll    operator/ (Point p, Point q) {return p.x * q.y - q.x * p.y;}
ll CCW(Point p, Point q, Point r) {return (q - p) / (r - q);}
ll Dist(Point p, Point q) {return pow(p.x - q.x, 2) + pow(p.y - q.y, 2);}
 
vector<Point> convex_hull(vector<Point> P){
    ll N = P.size();
    sort(P.begin(), P.end());
    sort(P.begin() + 1, P.end(), [&](Point a, Point b) -> bool {
        if(CCW(P[0], a, b) != CCW(P[0], b, a)) return CCW(P[0], a, b) < CCW(P[0], b, a);
        else if(a.x != b.x) return a.x < b.x;
        else return a.y < b.y;
    });
    vector<Point> H;
    for(int i = 0; i < N; i++){
        while(H.size() >= 2 && CCW(H[H.size() - 2], H[H.size() - 1], P[i]) >= 0) H.pop_back();
        H.push_back(P[i]);
    }
    return H;
}
ll rotating_callipers(vector<Point> P){
    P = convex_hull(P);
    ll N = P.size();
    ll L = 0, R = 0;
    for(int i = 1; i < N; i++){
        if(P[i].x < P[L].x) L = i;
        if(P[i].x > P[R].x) R = i;
    }
    ll ans = Dist(P[L], P[R]);
    for(int i = 0; i < N; i++){
        if((P[(L + 1) % N] - P[L]) / (P[(R + 1) % N] - P[R]) > 0){
            L = (L + 1) % N;
        } else {
            R = (R + 1) % N;
        }
        ans = max(ans, Dist(P[L], P[R]));
    }
    return ans;
}
ll N, T;
pair<Point, Point> A[30005];
ll f(ll t){
    vector<Point> P(N);
    for(int i = 0; i < N; i++){
        P[i].x = A[i].x.x + A[i].y.x * t;
        P[i].y = A[i].x.y + A[i].y.y * t;
    }
    return rotating_callipers(P);
}
 
int main(){
    cin.tie(0) -> sync_with_stdio(false);
 
    cin >> N >> T;
    for(int i = 0; i < N; i++){
        cin >> A[i].x.x >> A[i].x.y >> A[i].y.x >> A[i].y.y;
    }
    ll L = 0, R = T;
    while(R - L > 3){
        ll p = (L * 2 + R) / 3, q = (L + R * 2) / 3;
        if(f(p) <= f(q)) R = q;
        else L = p;
    }
    ll mn = 1e18, idx = 0;
    for(int i = L; i <= R; i++){
        ll v = f(i);
        if(mn > v){
            mn = v;
            idx = i;
        }
    }
    cout << idx << '\n' << mn;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 11 ms 340 KB Output is correct
12 Correct 12 ms 468 KB Output is correct
13 Correct 17 ms 352 KB Output is correct
14 Correct 13 ms 352 KB Output is correct
15 Correct 12 ms 440 KB Output is correct
16 Correct 10 ms 460 KB Output is correct
17 Correct 7 ms 340 KB Output is correct
18 Correct 8 ms 436 KB Output is correct
19 Correct 9 ms 436 KB Output is correct
20 Correct 16 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 3364 KB Output is correct
2 Correct 101 ms 3156 KB Output is correct
3 Correct 96 ms 3196 KB Output is correct
4 Correct 72 ms 4316 KB Output is correct
5 Correct 82 ms 3344 KB Output is correct
6 Correct 83 ms 4272 KB Output is correct
7 Correct 66 ms 3252 KB Output is correct
8 Correct 51 ms 3060 KB Output is correct
9 Correct 87 ms 4320 KB Output is correct
10 Correct 118 ms 3388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 11 ms 340 KB Output is correct
12 Correct 12 ms 468 KB Output is correct
13 Correct 17 ms 352 KB Output is correct
14 Correct 13 ms 352 KB Output is correct
15 Correct 12 ms 440 KB Output is correct
16 Correct 10 ms 460 KB Output is correct
17 Correct 7 ms 340 KB Output is correct
18 Correct 8 ms 436 KB Output is correct
19 Correct 9 ms 436 KB Output is correct
20 Correct 16 ms 440 KB Output is correct
21 Correct 126 ms 3364 KB Output is correct
22 Correct 101 ms 3156 KB Output is correct
23 Correct 96 ms 3196 KB Output is correct
24 Correct 72 ms 4316 KB Output is correct
25 Correct 82 ms 3344 KB Output is correct
26 Correct 83 ms 4272 KB Output is correct
27 Correct 66 ms 3252 KB Output is correct
28 Correct 51 ms 3060 KB Output is correct
29 Correct 87 ms 4320 KB Output is correct
30 Correct 118 ms 3388 KB Output is correct
31 Correct 568 ms 3384 KB Output is correct
32 Correct 535 ms 3304 KB Output is correct
33 Correct 544 ms 3204 KB Output is correct
34 Correct 581 ms 3424 KB Output is correct
35 Correct 363 ms 3468 KB Output is correct
36 Correct 476 ms 4184 KB Output is correct
37 Correct 369 ms 3404 KB Output is correct
38 Correct 224 ms 3432 KB Output is correct
39 Correct 411 ms 3500 KB Output is correct
40 Correct 517 ms 3288 KB Output is correct
41 Correct 498 ms 4276 KB Output is correct
42 Correct 453 ms 4288 KB Output is correct