답안 #466727

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
466727 2021-08-20T14:15:37 Z palilo 먼 별 (KOI16_dist) C++17
2 / 100
67 ms 1184 KB
#include <bits/stdc++.h>
using namespace std;

template <class T>
bool chmin(T& _old, T _new) { return _old > _new && (_old = _new, true); }
template <class T>
bool chmax(T& _old, T _new) { return _old < _new && (_old = _new, true); }

struct star_t {
    int x, y, dx, dy;
};

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
#ifdef palilo
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    int n, t;
    cin >> n >> t;
    vector<star_t> a(n);
    for (auto& [x, y, dx, dy] : a) {
        cin >> x >> y >> dx >> dy;
    }
    auto cross2 = [&](const pair<int, int>& u, const pair<int, int>& v) {
        return int64_t(u.first) * v.second - int64_t(u.second) * v.first;
    };
    auto cross3 = [&](const pair<int, int>& o, const pair<int, int>& u, const pair<int, int>& v) {
        return int64_t(u.first - o.first) * (v.second - o.second) -
               int64_t(u.second - o.second) * (v.first - o.first);
    };
    auto dist = [&](const pair<int, int>& u, const pair<int, int>& v) {
        int64_t dx = u.first - v.first, dy = u.second - v.second;
        return dx * dx + dy * dy;
    };
    vector<pair<int, int>> star(n), hull(n);
    auto f = [&](int dt) -> int64_t {
        // sort ccw
        transform(a.begin(), a.end(), star.begin(), [&](const auto& star) {
            return pair(star.x + star.dx * dt, star.y + star.dy * dt);
        });
        iter_swap(star.begin(), min_element(star.begin(), star.end()));
        sort(next(star.begin()), star.end(), [&](const auto& lhs, const auto& rhs) {
            const auto c = cross3(star.front(), lhs, rhs);
            return c ? c > 0 : dist(star.front(), lhs) < dist(star.front(), rhs);
        });
        // convex hull
        hull.clear();
        hull.emplace_back(star[0]);
        hull.emplace_back(star[1]);
        for (int i = 2; i < n; ++i) {
            while (hull.size() != 1 && cross3(hull.end()[-2], hull.end()[-1], star[i]) <= 0) {
                hull.pop_back();
            }
            hull.emplace_back(star[i]);
        }
        if (hull.size() == 2 && hull[0] == hull[1]) {
            return 0;
        }
        // calipers
        int64_t ret = 0;
        for (size_t i = 0, j = 1, j2; i < j; ++i) {
            for (j2 = j == hull.size() - 1 ? 0 : j + 1;; j = j2) {
                chmax(ret, dist(hull[i], hull[j]));
                pair u(hull[j2].first - hull[j].first, hull[j2].second - hull[j].second);
                pair v(hull[i + 1].first - hull[i].first, hull[i + 1].second - hull[i].second);
                if (cross2(u, v) >= 0) break;
            }
        }
        return ret;
    };
    int lo = 0, hi = t;
    while (lo != hi) {
        const auto ml = lo + (hi - lo) / 3;
        const auto mr = hi - (hi - lo) / 3;
        f(ml) <= f(mr) ? hi = mr - 1 : lo = ml + 1;
    }
    cout << lo << '\n';
    cout << f(lo);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Incorrect 11 ms 340 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 67 ms 1184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Incorrect 11 ms 340 KB Output isn't correct
12 Halted 0 ms 0 KB -