結果

問題 No.622 点と三角柱の内外判定
ユーザー RyutoRyuto
提出日時 2017-12-23 00:15:19
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 78 ms / 1,500 ms
コード長 1,851 bytes
コンパイル時間 517 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 71,352 KB
最終ジャッジ日時 2023-08-22 21:35:11
合計ジャッジ時間 4,301 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,000 KB
testcase_01 AC 75 ms
71,312 KB
testcase_02 AC 77 ms
71,192 KB
testcase_03 AC 77 ms
71,152 KB
testcase_04 AC 76 ms
71,316 KB
testcase_05 AC 76 ms
71,156 KB
testcase_06 AC 77 ms
71,156 KB
testcase_07 AC 76 ms
71,228 KB
testcase_08 AC 76 ms
71,260 KB
testcase_09 AC 77 ms
71,004 KB
testcase_10 AC 76 ms
71,192 KB
testcase_11 AC 75 ms
71,184 KB
testcase_12 AC 75 ms
71,152 KB
testcase_13 AC 76 ms
70,968 KB
testcase_14 AC 78 ms
71,316 KB
testcase_15 AC 76 ms
70,940 KB
testcase_16 AC 76 ms
71,128 KB
testcase_17 AC 77 ms
71,352 KB
testcase_18 AC 77 ms
71,136 KB
testcase_19 AC 75 ms
71,156 KB
testcase_20 AC 76 ms
71,148 KB
testcase_21 AC 77 ms
71,136 KB
testcase_22 AC 77 ms
71,000 KB
testcase_23 AC 75 ms
71,348 KB
testcase_24 AC 77 ms
71,336 KB
testcase_25 AC 78 ms
71,312 KB
testcase_26 AC 77 ms
71,000 KB
testcase_27 AC 78 ms
71,004 KB
testcase_28 AC 78 ms
71,088 KB
testcase_29 AC 76 ms
71,188 KB
testcase_30 AC 77 ms
71,080 KB
testcase_31 AC 76 ms
70,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python


def dot(A, B):
    return A[0]*B[0] + A[1]*B[1] + A[2]*B[2]


def cross(A, B):
    X = A[1]*B[2] - A[2]*B[1]
    Y = A[2]*B[0] - A[0]*B[2]
    Z = A[0]*B[1] - A[1]*B[0]
    return [X, Y, Z]


def inverse(A):
    det = A[0][0]*A[1][1]*A[2][2] + A[0][1]*A[1][2]*A[2][0]
    det += A[0][2]*A[1][0]*A[2][1] - A[0][0]*A[1][2]*A[2][1]
    det += - A[0][2]*A[1][1]*A[2][0] - A[0][1]*A[1][0]*A[2][2]
    A11 = (-1)**2 * (A[1][1]*A[2][2] - A[1][2]*A[2][1]) / det
    A12 = (-1)**3 * (A[1][0]*A[2][2] - A[1][2]*A[2][0]) / det
    A13 = (-1)**4 * (A[1][0]*A[2][1] - A[1][1]*A[2][0]) / det
    A21 = (-1)**3 * (A[0][1]*A[2][2] - A[0][2]*A[2][1]) / det
    A22 = (-1)**4 * (A[0][0]*A[2][2] - A[0][2]*A[2][0]) / det
    A23 = (-1)**5 * (A[0][0]*A[2][1] - A[0][1]*A[2][0]) / det
    A31 = (-1)**4 * (A[0][1]*A[1][2] - A[0][2]*A[1][1]) / det
    A32 = (-1)**5 * (A[0][0]*A[1][2] - A[0][2]*A[1][0]) / det
    A33 = (-1)**6 * (A[0][0]*A[1][1] - A[0][1]*A[1][0]) / det
    return [[A11, A21, A31], [A12, A22, A32], [A13, A23, A33]]


A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
D = [int(x) for x in input().split()]

AB = [b - a for (a, b) in zip(A, B)]
AC = [c - a for (a, c) in zip(A, C)]
AD = [d - a for (a, d) in zip(A, D)]
BC = [c - b for (b, c) in zip(B, C)]
BA = [-x for x in AB]

Z = cross(AB, AC)
M = inverse([AB, AC, Z])
Co = [AD[0]*x + AD[1]*y + AD[2]*z for (x, y, z) in zip(M[0], M[1], M[2])]
if Co[0] > 0 and Co[1] > 0 and Co[0] < 1 and Co[1] < 1:
    Dp = [Co[0]*b + Co[1]*c + Co[2]*z for (b, c, z) in zip(AB, AC, Z)]
    Mp = inverse([AB, BC, Z])
    Cp = [Dp[0]*x + Dp[1]*y + Dp[2]*z for (x, y, z) in zip(Mp[0], Mp[1], Mp[2])]
    if Cp[0] > 0 and Cp[1] > 0 and Cp[0] < 1 and Cp[1] < 1:
        print('YES')
    else:
        print('NO')
else:
    print('NO')
0