Submission #681414

#TimeUsernameProblemLanguageResultExecution timeMemory
681414Kamisama먼 별 (KOI16_dist)C++14
100 / 100
229 ms3156 KiB
#include <iostream> #include <cstdlib> #include <climits> #include <algorithm> using namespace std; const int MAXN = 3e4 + 7; struct Star { long long x, y, dx, dy; Star(long long x=0, long long y=0, long long dx=0, long long dy=0) : x(x), y(y), dx(dx), dy(dy) {} Star operator-(const Star &other) const { return Star(x - other.x, y - other.y); } long long operator%(const Star &other) const { return x * other.y - y * other.x; } }; int n, t, hull_size; Star a[MAXN], p[MAXN]; Star convex_hull[MAXN]; int ccw(const Star &A, const Star &B, const Star &C) { long long res = A % B + B % C + C % A; return (res > 0) - (res < 0); } long long get_distance(const Star &A, const Star &B) { long long dx = A.x - B.x; long long dy = A.y - B.y; return dx * dx + dy * dy; } long long solve(int k) { for(int i = 1; i <= n; i++) { p[i] = Star(a[i].x + k * a[i].dx, a[i].y + k * a[i].dy); } swap(p[1], *min_element(p + 1, p + n + 1, [](const Star &A, const Star &B) { return A.x < B.x || (A.x == B.x && A.y < B.y); })); sort(p + 2, p + n + 1, [](const Star &A, const Star &B) { int not_linear = ccw(p[1], A, B); if(not_linear) return not_linear > 0; return get_distance(p[1], A) < get_distance(p[1], B); }); hull_size = 0; for(int i = 1; i <= n; i++) { while(hull_size >= 2 && ccw(convex_hull[hull_size - 1], convex_hull[hull_size], p[i]) <= 0){ hull_size--; } convex_hull[++hull_size] = p[i]; } long long res = 0; for(int i = 1, j = 1; i <= hull_size; i++) { while(j < hull_size && (convex_hull[i + 1] - convex_hull[i]) % (convex_hull[j + 1] - convex_hull[j]) >= 0) { res = max(res, get_distance(convex_hull[i], convex_hull[j])); j++; } res = max(res, get_distance(convex_hull[i], convex_hull[j])); } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> t; for(int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y >> a[i].dx >> a[i].dy; int l = 0, r = t - 1; while(l <= r) { int m = (l + r) / 2; if(solve(m) > solve(m + 1)) l = m + 1; else r = m - 1; } cout << l << '\n' << solve(l); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...