結果

問題 No.240 ナイト散歩
ユーザー Hitoshi Hayakawa
提出日時 2019-09-05 08:18:42
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 691 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-12-31 20:36:21
合計ジャッジ時間 2,564 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

X, Y = map(int, input().split())
from collections import deque

def bfs(x, y, X, Y, i):

    d = deque()
    d.append((x, y, i))

    while d:
        (x, y, i) = d.popleft()

        if i == 3+1:
            return False
        if x == X and y == Y:
            return True

        d.append((x-2, y-1, i+1))
        d.append((x-2, y+1, i+1))
        d.append((x-1, y-2, i+1))
        d.append((x-1, y+2, i+1))
        d.append((x+1, y-2, i+1))
        d.append((x+1, y+2, i+1))
        d.append((x+2, y-1, i+1))
        d.append((x+2, y+1, i+1))


print('YES' if bfs(0,0,X,Y,0) else 'NO')
0