結果

問題 No.2564 衝突予測
ユーザー tipstar0125tipstar0125
提出日時 2023-12-02 16:47:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 4,396 bytes
コンパイル時間 874 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 91,472 KB
最終ジャッジ日時 2023-12-02 16:47:35
合計ジャッジ時間 8,501 ms
ジャッジサーバーID
(参考情報)
judge13 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
88,272 KB
testcase_01 AC 158 ms
88,272 KB
testcase_02 AC 156 ms
88,272 KB
testcase_03 AC 615 ms
90,832 KB
testcase_04 AC 602 ms
90,960 KB
testcase_05 AC 617 ms
91,216 KB
testcase_06 AC 594 ms
90,960 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from __future__ import annotations

import array
import bisect
import copy
import fractions
import heapq
import itertools
import math
import random
import re
import string
import sys
import time
from collections import defaultdict, deque
from functools import lru_cache

sys.setrecursionlimit(10**6)


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return list(input().split())


def read_str():
    return input()


def is_prime(n: int) -> bool:
    if n < 2:
        return False
    i = 2
    ok = True
    while i * i <= n:
        if n % i == 0:
            ok = False
        i += 1
    return ok


def eratosthenes(n: int) -> list[bool]:

    is_prime_list = ([False, True] * (n // 2 + 1))[0 : n + 1]
    is_prime_list[1] = False
    is_prime_list[2] = True
    for i in range(3, n + 1, 2):
        if not (is_prime_list[i]):
            continue
        if i * i > n:
            break
        for k in range(i * i, n + 1, i):
            is_prime_list[k] = False
    return is_prime_list


def legendre(n: int, p: int) -> int:
    cnt = 0
    pp = p
    while pp <= n:
        cnt += n // pp
        pp *= p

    return cnt


def prime_factorize(n: int) -> defaultdict[int, int]:
    nn = n
    i = 2
    d: defaultdict[int, int] = defaultdict(int)
    while i * i <= n:
        while nn % i == 0:
            d[i] += 1
            nn //= i
        i += 1
    if nn != 1:
        d[nn] += 1
    return d


def make_divisors(n: int) -> list[int]:
    i = 1
    ret = []
    while i * i <= n:
        if n % i == 0:
            ret.append(i)
            if i != n // i:
                ret.append(n // i)
        i += 1
    ret.sort()
    return ret


def gcd(a: int, b: int) -> int:

    if a == 0:
        return b
    else:
        return gcd(b % a, a)


def lcm(a: int, b: int) -> int:
    return a * b // gcd(a, b)


def ext_gcd(a: int, b: int) -> tuple[int, int, int]:
    if a == 0:
        return (0, 1, b)
    x, y, g = ext_gcd(b % a, a)
    return (y - b // a * x, x, g)

class UnionFind:
    def __init__(self, n):
        self.parent = [-1] * n
        self.size = n

    def find(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def merge(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x != y:
            if self.parent[x] > self.parent[y]:
                x, y = y, x
            self.parent[x] += self.parent[y]
            self.parent[y] = x
            self.size -= 1
            return True
        else:
            return False

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.parent[self.find(x)]



def solve():
    
    x1,y1,d1=read_str_list()
    x1=int(x1)
    y1=int(y1)
    x2,y2,d2=read_str_list()    
    x2=int(x2)
    y2=int(y2)
    
    if x1==x2:
        if y1<y2 and d1=="U" and d2=="D":
            print("Yes")
            return
        if y1>y2 and d1=="D" and d2=="U":
            print("Yes")
            return
    if y1==y2:
        if x1<x2 and d1=="R" and d2=="L":
            print("Yes")
            return
        if x1>x2 and d1=="L" and d2=="R":
            print("Yes")
            return

    if d1=="U" and y2>y1:
        diff=y2-y1
        if d2=="L" and [x1,y1+diff]==[x2-diff,y2]:
            print("Yes")
            return
        if d2=="R" and [x1,y1+diff]==[x2+diff,y2]:
            print("Yes")
            return
    if d1=="D" and y2<y1:
        diff=y1-y2
        if d2=="L" and [x1,y1-diff]==[x2-diff,y2]:
            print("Yes")
            return
        if d2=="R" and [x1,y1-diff]==[x2+diff,y2]:
            print("Yes")
            return
    if d1=="R" and x2>x1:
        diff=x2-x1
        if d2=="U" and [x1+diff,y1]==[x2+diff,y2]:
            print("Yes")
            return
        if d2=="D" and [x1+diff,y1]==[x2-diff,y2]:
            print("Yes")
            return
    if d1=="L" and x2<x1:
        diff=x1-x2
        if d2=="U" and [x1-diff,y1]==[x2+diff,y2]:
            print("Yes")
            return
        if d2=="D" and [x1-diff,y1]==[x2-diff,y2]:
            print("Yes")
            return
        
    print("No")

def main():
    t = read_int()
    for _ in range(t):
        solve()


main()
0