結果

問題 No.2012 Largest Triangle
ユーザー 👑 ygussanyygussany
提出日時 2022-07-15 23:18:42
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 1,493 bytes
コンパイル時間 993 ms
コンパイル使用メモリ 35,712 KB
実行使用メモリ 16,504 KB
最終ジャッジ日時 2023-09-10 05:04:26
合計ジャッジ時間 7,744 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,760 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 96 ms
12,252 KB
testcase_17 AC 97 ms
12,184 KB
testcase_18 AC 96 ms
12,060 KB
testcase_19 AC 96 ms
12,168 KB
testcase_20 AC 96 ms
12,252 KB
testcase_21 AC 96 ms
12,180 KB
testcase_22 AC 96 ms
12,184 KB
testcase_23 AC 96 ms
12,316 KB
testcase_24 AC 96 ms
12,056 KB
testcase_25 AC 96 ms
12,232 KB
testcase_26 AC 96 ms
12,120 KB
testcase_27 AC 96 ms
12,160 KB
testcase_28 AC 95 ms
12,148 KB
testcase_29 AC 96 ms
12,208 KB
testcase_30 AC 95 ms
12,152 KB
testcase_31 TLE -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast,unroll-loops")
#include <stdio.h>
#include <math.h>

typedef struct {
	double x, y;
} point;

double distance(point p, point q)
{
	return sqrt((p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y));
}

double area_of_triangle(point a, point b, point c)
{
	double p, q, r, s;
	p = distance(a, b);
	q = distance(b, c);
	r = distance(c, a);
	s = (p + q + r) / 2.0;
	return sqrtl(s * (s - p) * (s - q) * (s - r));
}

typedef struct {
	double key;
	int id;
} data;

void merge_sort(int n, data x[])
{
	static data y[1000001] = {};
	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(double* a, double b)
{
	if (*a < b) *a = b;
}

int main()
{
	int i, N;
	point p[200001];
	data d[200001];
	scanf("%d", &N);
	for (i = 1, p[0].x = 0.0, p[0].y = 0.0; i <= N; i++) {
		scanf("%lf %lf", &(p[i].x), &(p[i].y));
		d[i-1].key = distance(p[0], p[i]);
		d[i-1].id = i;
	}
	merge_sort(N, d);
	
	int j;
	double ans = 0.0;
	for (i = N - 1; i >= 0; i--) {
		for (j = i - 1; j >= 0; j--) {
			if (ans >= d[i].key * d[j].key / 2.0) break;
			chmax(&ans, area_of_triangle(p[0], p[d[i].id], p[d[j].id]));
		}
	}
	printf("%lld\n", (long long)(ans * 2.0 + 0.5));
	fflush(stdout);
	return 0;
}
0