Submission #466723

#TimeUsernameProblemLanguageResultExecution timeMemory
466723palilo먼 별 (KOI16_dist)C++17
0 / 100
67 ms1956 KiB
#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) -> int { // 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]); } // 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); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...