結果

問題 No.3005 トレミーの問題
ユーザー ジュ・ビオレ・グレイス
提出日時 2025-01-11 00:22:58
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 974 bytes
コンパイル時間 5,075 ms
コンパイル使用メモリ 102,016 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-01-12 14:45:56
合計ジャッジ時間 4,495 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.algorithm, std.range, std.array, std.conv, std.typecons, std.bigint;

alias Point = Tuple!(BigInt, "x", BigInt, "y");

bool same_line(Point a, Point b, Point c) {
	return (b.x-a.x)*(c.y-a.y) == (b.y-a.y)*(c.x-a.x);
}

BigInt distance(Point a, Point b) {
	return ((a.x - b.x)^^2 + (a.y - b.y)^^2);
}

BigInt product(Point v, Point w) {
	return (v.x*w.x + v.y*w.y)^^2;
}

Point readpoint() {
	auto tmp = readln.split;
	return Point(BigInt(tmp[0]), BigInt(tmp[1]));
}

void main() {
	auto A = readpoint(), B = readpoint(), C = readpoint(), D = readpoint();
	
	if (same_line(A, B, C) || same_line(A, B, D)) {
		writeln("NO");
		return;
	}
	
	// vectors
	auto
		DA = Point(A.x - D.x, A.y - D.y),
		DB = Point(B.x - D.x, B.y - D.y),
		CA = Point(A.x - C.x, A.y - C.y),
		CB = Point(B.x - C.x, B.y - C.y);
	
	if (product(DA, DB) * distance(C, A) * distance(C, B) == product(CA, CB) * distance(D, A) * distance(D, B))
		writeln("YES");
	else
		writeln("NO");
}
0