結果
問題 | No.2012 Largest Triangle |
ユーザー | ygussany |
提出日時 | 2022-07-16 00:37:42 |
言語 | C (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,076 bytes |
コンパイル時間 | 312 ms |
コンパイル使用メモリ | 35,572 KB |
実行使用メモリ | 14,636 KB |
最終ジャッジ日時 | 2024-06-27 22:36:12 |
合計ジャッジ時間 | 16,705 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,944 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 1 ms
6,944 KB |
testcase_14 | AC | 1 ms
6,940 KB |
testcase_15 | AC | 1 ms
6,940 KB |
testcase_16 | AC | 148 ms
14,624 KB |
testcase_17 | AC | 151 ms
14,448 KB |
testcase_18 | AC | 148 ms
14,572 KB |
testcase_19 | AC | 150 ms
14,592 KB |
testcase_20 | AC | 146 ms
14,580 KB |
testcase_21 | AC | 147 ms
14,612 KB |
testcase_22 | AC | 150 ms
14,592 KB |
testcase_23 | AC | 147 ms
14,584 KB |
testcase_24 | AC | 148 ms
14,416 KB |
testcase_25 | AC | 147 ms
14,636 KB |
testcase_26 | AC | 142 ms
14,472 KB |
testcase_27 | AC | 147 ms
14,556 KB |
testcase_28 | AC | 146 ms
14,628 KB |
testcase_29 | AC | 140 ms
14,628 KB |
testcase_30 | AC | 135 ms
14,604 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | AC | 2 ms
6,940 KB |
testcase_37 | AC | 2 ms
6,944 KB |
testcase_38 | AC | 2 ms
6,940 KB |
testcase_39 | AC | 2 ms
6,940 KB |
testcase_40 | AC | 2 ms
6,940 KB |
testcase_41 | AC | 25 ms
9,500 KB |
ソースコード
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <sys/time.h> const double pi = 3.14159265358979; typedef struct { long long x, y; } point; double distance(point p, point q) { return sqrt((double)(p.x - q.x) * (p.x - q.x) + (double)(p.y - q.y) * (p.y - q.y)); } int is_above(point p, point q, point r) { if (p.x == q.x) { if (r.x == p.x) return 0; else if (r.x < p.x) return 1; else return -1; } if (p.x == r.x) { if (p.y < r.y) return 1; else if (p.y > r.y) return -1; else return 0; } point t; if (q.x < p.x) { t = q; q = p; p = t; } if ((q.y - p.y) * (r.x - p.x) < (r.y - p.y) * (q.x - p.x)) return 1; else if ((q.y - p.y) * (r.x - p.x) > (r.y - p.y) * (q.x - p.x)) return -1; else return 0; } // Twice of the area of the triangle pqr long long area_of_triangle(point p, point q, point r) { long long L, R, B, T; L = p.x; if (L > q.x) L = q.x; if (L > r.x) L = r.x; R = p.x; if (R < q.x) R = q.x; if (R < r.x) R = r.x; B = p.y; if (B > q.y) B = q.y; if (B > r.y) B = r.y; T = p.y; if (T < q.y) T = q.y; if (T < r.y) T = r.y; long long ans = (R - L) * (T - B) * 2 - (llabs(p.x - q.x) * llabs(p.y - q.y) + llabs(q.x - r.x) * llabs(q.y - r.y) + llabs(r.x - p.x) * llabs(r.y - p.y)); if (p.x != L && p.x != R && p.y != B && p.y != T) { if (is_above(q, r, p) == 1) { if ((q.x == L && q.y == B) || (q.x == R && q.y == T)) ans -= (p.x - L) * (T - p.y); else ans -= (R - p.x) * (T - p.y); } else { if ((q.x == L && q.y == B) || (q.x == R && q.y == T)) ans -= (R - p.x) * (p.y - B); else ans -= (p.x - L) * (p.y - B); } } else if (q.x != L && q.x != R && q.y != B && q.y != T) { if (is_above(r, p, q) == 1) { if ((r.x == L && r.y == B) || (r.x == R && r.y == T)) ans -= (q.x - L) * (T - q.y); else ans -= (R - q.x) * (T - q.y); } else { if ((r.x == L && r.y == B) || (r.x == R && r.y == T)) ans -= (R - q.x) * (q.y - B); else ans -= (q.x - L) * (q.y - B); } } else if (r.x != L && r.x != R && r.y != B && r.y != T) { if (is_above(p, q, r) == 1) { if ((p.x == L && p.y == B) || (p.x == R && p.y == T)) ans -= (r.x - L) * (T - r.y); else ans -= (R - r.x) * (T - r.y); } else { if ((p.x == L && p.y == B) || (p.x == R && p.y == T)) ans -= (r.x - L) * (r.y - B); else ans -= (R - r.x) * (r.y - B); } } return ans; } typedef struct { double key; int id; } data; void merge_sort(int n, data x[]) { static data y[200001] = {}; if (n <= 1) return; merge_sort(n / 2, &(x[0])); merge_sort((n + 1) / 2, &(x[n/2])); int i, p, q; for (i = 0, p = 0, q = n / 2; i < n; i++) { if (p >= n / 2) y[i] = x[q++]; else if (q >= n) y[i] = x[p++]; else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++]; } for (i = 0; i < n; i++) x[i] = y[i]; } void chmax(long long* a, long long b) { if (*a < b) *a = b; } int main() { struct timeval tt; double beg, cur; gettimeofday(&tt, NULL); beg = tt.tv_sec + (double)tt.tv_usec / 1000000; int i, j, N; long long ans = 0; point p[200001]; data d[400001]; scanf("%d", &N); for (i = 1, p[0].x = 0, p[0].y = 0; i <= N; i++) { scanf("%lld %lld", &(p[i].x), &(p[i].y)); d[i-1].key = atan2(p[i].y, p[i].x); d[i-1].id = i; } merge_sort(N, d); for (i = 0; i < N; i++) { d[i+N].key = d[i].key + pi * 2.0; d[i+N].id = d[i].id; } for (i = 0, j = 1; i < N; i++) { while (fabs(d[j+1].key - d[i].key - pi / 2.0) < fabs(d[j].key - d[i].key - pi / 2.0)) j++; chmax(&ans, area_of_triangle(p[0], p[d[i].id], p[d[j-1].id])); chmax(&ans, area_of_triangle(p[0], p[d[i].id], p[d[j].id])); chmax(&ans, area_of_triangle(p[0], p[d[i].id], p[d[j+1].id])); } for (i = 1; i <= N; i++) { d[i-1].key = distance(p[0], p[i]); d[i-1].id = i; } merge_sort(N, d); for (i = N - 1; i >= 0; i--) { for (j = i - 1; j >= 0; j--) { if (ans - d[i].key * d[j].key >= 0.0) break; chmax(&ans, area_of_triangle(p[0], p[d[i].id], p[d[j].id])); } gettimeofday(&tt, NULL); cur = tt.tv_sec + (double)tt.tv_usec / 1000000; if (cur - beg > 2.49) break; } printf("%lld\n", ans); fflush(stdout); return 0; }