結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
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 -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘main’ 内:
main.c:66:31: 警告: 互換性のないポインタ型から 1 番目の ‘chmax’ の引数に渡しています [-Wincompatible-pointer-types]
   66 |                         chmax(&ans, tmp * fabs(sin(theta[d[j].id] - theta[d[i].id])));
      |                               ^~~~
      |                               |
      |                               double *
main.c:35:25: 備考: expected ‘long double *’ but argument is of type ‘double *’
   35 | void chmax(long double* a, long double b)
      |            ~~~~~~~~~~~~~^

ソースコード

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(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;
	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