結果

問題 No.2012 Largest Triangle
ユーザー 👑 ygussanyygussany
提出日時 2022-07-15 23:38:05
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,774 bytes
コンパイル時間 417 ms
コンパイル使用メモリ 31,624 KB
実行使用メモリ 24,188 KB
最終ジャッジ日時 2023-09-10 05:36:53
合計ジャッジ時間 8,009 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,304 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
6,292 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <math.h>
#include <sys/time.h>

typedef struct {
	long double x, y;
} point;

long double distance(point p, point q)
{
	return sqrtl((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 {
	long 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 double* a, long double 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, N;
	long double theta[200001];
	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));
		theta[i] = atan2l(p[i].y, p[i].x);
		d[i-1].key = distance(p[0], p[i]);
		d[i-1].id = i;
	}
	merge_sort(N, d);
	
	int j;
	long double ans = 0.0, tmp;
	for (i = N - 1; i >= 0; i--) {
		for (j = i - 1; j >= 0; j--) {
			tmp = d[i].key * d[j].key * 0.5;
			if (ans >= tmp) break;
			chmax(&ans, tmp * sinl(fabsl(theta[j] - theta[i])));
		}
		gettimeofday(&tt, NULL);
		cur = tt.tv_sec + (double)tt.tv_usec / 1000000;
		if (cur - beg > 2.48) break;
	}
	printf("%lld\n", (long long)(ans * 2.0 + 0.5));
	fflush(stdout);
	return 0;
}
0