結果

問題 No.2012 Largest Triangle
ユーザー 👑 ygussanyygussany
提出日時 2022-07-15 23:47:04
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,536 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 31,868 KB
実行使用メモリ 13,396 KB
最終ジャッジ日時 2023-09-10 05:55:35
合計ジャッジ時間 16,842 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
6,312 KB
testcase_02 AC 1 ms
4,412 KB
testcase_03 AC 2 ms
4,412 KB
testcase_04 AC 1 ms
6,316 KB
testcase_05 AC 2 ms
4,400 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
6,400 KB
testcase_08 AC 2 ms
4,428 KB
testcase_09 AC 1 ms
6,324 KB
testcase_10 AC 1 ms
4,412 KB
testcase_11 AC 2 ms
4,460 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
6,304 KB
testcase_14 AC 1 ms
6,456 KB
testcase_15 AC 1 ms
6,312 KB
testcase_16 AC 119 ms
13,152 KB
testcase_17 AC 119 ms
13,148 KB
testcase_18 AC 118 ms
13,148 KB
testcase_19 AC 118 ms
13,148 KB
testcase_20 AC 118 ms
13,148 KB
testcase_21 AC 118 ms
13,148 KB
testcase_22 AC 117 ms
13,228 KB
testcase_23 AC 118 ms
13,148 KB
testcase_24 AC 118 ms
13,140 KB
testcase_25 AC 118 ms
13,292 KB
testcase_26 AC 119 ms
13,292 KB
testcase_27 AC 118 ms
13,232 KB
testcase_28 AC 119 ms
13,288 KB
testcase_29 AC 119 ms
13,092 KB
testcase_30 AC 119 ms
13,136 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
6,332 KB
testcase_38 AC 2 ms
6,500 KB
testcase_39 AC 2 ms
6,552 KB
testcase_40 AC 2 ms
6,416 KB
testcase_41 AC 24 ms
7,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <math.h>
#include <sys/time.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));
}

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(double* a, 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;
	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] = atan2(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;
	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 * fabs(sin(theta[d[j].id] - theta[d[i].id])));
		}
		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