提出 #78140658
ソースコード 拡げる
Copy
#include <stdio.h>int main(void) {int T, tc;if (scanf("%d", &T) != 1) return 1;for (tc = 0; tc < T; tc++) {int Px, Py, Qx, Qy, Rx, Ry, Sx, Sy;long long a, b, c, d, e, f;if (scanf("%d%d%d%d%d%d%d%d", &Px, &Py, &Qx, &Qy, &Rx, &Ry, &Sx, &Sy) != 8) return 1;a = 2LL * Px - 2LL * Qx;b = 2LL * Py - 2LL * Qy;c = (long long)Px * Px + (long long)Py * Py - (long long)Qx * Qx - (long long)Qy * Qy;d = 2LL * Rx - 2LL * Sx;e = 2LL * Ry - 2LL * Sy;f = (long long)Rx * Rx + (long long)Ry * Ry - (long long)Sx * Sx - (long long)Sy * Sy;if (b * d == a * e) {if (a == 0? (__int128_t)c * e == (__int128_t)b * f: (__int128_t)c * d == (__int128_t)a * f) {
#include <stdio.h>
int main(void) {
int T, tc;
if (scanf("%d", &T) != 1) return 1;
for (tc = 0; tc < T; tc++) {
int Px, Py, Qx, Qy, Rx, Ry, Sx, Sy;
long long a, b, c, d, e, f;
if (scanf("%d%d%d%d%d%d%d%d", &Px, &Py, &Qx, &Qy, &Rx, &Ry, &Sx, &Sy) != 8) return 1;
a = 2LL * Px - 2LL * Qx;
b = 2LL * Py - 2LL * Qy;
c = (long long)Px * Px + (long long)Py * Py - (long long)Qx * Qx - (long long)Qy * Qy;
d = 2LL * Rx - 2LL * Sx;
e = 2LL * Ry - 2LL * Sy;
f = (long long)Rx * Rx + (long long)Ry * Ry - (long long)Sx * Sx - (long long)Sy * Sy;
if (b * d == a * e) {
if (
a == 0
? (__int128_t)c * e == (__int128_t)b * f
: (__int128_t)c * d == (__int128_t)a * f
) {
/* 垂直二等分線は重なる */
puts("Yes");
} else {
/* 垂直二等分線は重ならず平行 */
puts("No");
}
} else {
/* 垂直二等分線が平行でない */
puts("Yes");
}
}
return 0;
}
/*
Yes iff
線分 (P_x, P_y) - (Q_x, Q_y) の垂直二等分線と、
線分 (R_x, R_y) - (S_x, S_y) の垂直二等分線が共通点を持つ
すなわち、一致 or 並行でない (傾きが違う)
(P_x - x)**2 + (P_y - y)**2 == (Q_x - x)**2 + (Q_y - y)**2
P_x**2 - 2*P_x*x + x**2 + P_y**2 - 2*P_y*y + y**2
== Q_x**2 - 2*Q_x*x + x**2 + Q_y**2 - 2*Q_y*y + y**2
(2*P_x - 2*Q_x)*x + (2*P_y - 2*Q_y)*y == P_x**2 + P_y**2 - Q_x**2 - Q_y**2
同様に
(2*R_x - 2*S_x)*x + (2*R_y - 2*S_y)*y == R_x**2 + R_y**2 - S_x**2 - S_y**2
これを
a*x + b*y == c … (1)
d*x + e*y == f … (2)
とする
平行 → (1) を d/a 倍して、左辺が (2) と一致する (ただし a != 0 のとき)
すなわち b * d / a == e
変形して b * d == a * e
a == 0 のときは、(P_x, P_y) と (Q_x, Q_y) は異なるので、必ず垂直二等分線はできる
ため、b != 0 のはずなので、d == 0 のとき、かつそのときのみこれを満たす
これは、2直線が平行であることになる
よって、a == 0 のときもこの式で判定できる
平行のとき、同一性判定をする
a != 0 のとき c * d / a == f すなわち c * d == a * f
a == 0 のとき c * e / b == f すなわち c * e == b * f
*/
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - Concentric Circles |
| ユーザ | mikecat |
| 言語 | C23 (GCC 14.2.0) |
| 得点 | 425 |
| コード長 | 2242 Byte |
| 結果 | AC |
| 実行時間 | 24 ms |
| メモリ | 1644 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 425 / 425 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00_sample_00.txt |
| All | 00_sample_00.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 01_small_07.txt, 02_random_1_00.txt, 03_random_2_00.txt, 04_random_3_00.txt, 05_random_4_00.txt, 06_random_5_00.txt, 07_random_6_00.txt, 08_random_7_00.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 1552 KiB |
| 01_small_00.txt | AC | 14 ms | 1568 KiB |
| 01_small_01.txt | AC | 13 ms | 1640 KiB |
| 01_small_02.txt | AC | 13 ms | 1504 KiB |
| 01_small_03.txt | AC | 13 ms | 1632 KiB |
| 01_small_04.txt | AC | 13 ms | 1552 KiB |
| 01_small_05.txt | AC | 13 ms | 1612 KiB |
| 01_small_06.txt | AC | 13 ms | 1640 KiB |
| 01_small_07.txt | AC | 3 ms | 1504 KiB |
| 02_random_1_00.txt | AC | 23 ms | 1552 KiB |
| 03_random_2_00.txt | AC | 24 ms | 1612 KiB |
| 04_random_3_00.txt | AC | 22 ms | 1504 KiB |
| 05_random_4_00.txt | AC | 22 ms | 1592 KiB |
| 06_random_5_00.txt | AC | 21 ms | 1644 KiB |
| 07_random_6_00.txt | AC | 22 ms | 1504 KiB |
| 08_random_7_00.txt | AC | 21 ms | 1504 KiB |