結果

問題 No.2564 衝突予測
ユーザー yaakiyu
提出日時 2023-12-02 15:51:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 1,846 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 78,464 KB
最終ジャッジ日時 2024-09-26 19:23:52
合計ジャッジ時間 3,947 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(1000000)

t = int(input())

for i in range(t):
    x,y,d = input().split()
    x,y = int(x), int(y)
    x2,y2,d2 = input().split()
    x2,y2 = int(x2), int(y2)
    if d in "RL" and d2 in "RL":
        # 横方向での衝突を考える
        if y != y2:
            print("No")
        elif x < x2:
            # a -> <- b の場合のみ衝突
            if d == "R" and d2 == "L":
                print("Yes")
            else:
                print("No")
        else:
            # b -> <- a の場合のみ衝突
            if d == "L" and d2 == "R":
                print("Yes")
            else:
                print("No")
        continue
    if d in "UD" and d2 in "UD":
        # 縦方向での衝突を考える
        if x != x2:
            print("No")
        elif y < y2:
            # ^ v の場合のみ衝突
            if d == "U" and d2 == "D":
                print("Yes")
            else:
                print("No")
        else:
            # v ^ の場合のみ衝突
            if d == "D" and d2 == "U":
                print("Yes")
            else:
                print("No")
        continue
    if d2 in "UD":
        # d1がUD、d2がRLになるように入れ替える
        x, y, d, x2, y2, d2 = x2, y2, d2, x, y, d
    # 衝突予想地点
    sx, sy = x, y2
    # ここを通るかどうかを確認する
    if not ((d == "U" and y < sy) or (d == "D" and y > sy)):
        # aが通らない
        print("No")
        continue
    if not ((d2 == "R" and x2 < sx) or (d2 == "L" and x2 > sx)):
        # bが通らない
        print("No")
        continue
    # 到着予想時刻の計算
    yosou_a = abs(sy-y)
    yosou_b = abs(sx-x2)
    if yosou_a == yosou_b:
        print("Yes")
    else:
        print("No")
0