結果

問題 No.240 ナイト散歩
ユーザー roarisroaris
提出日時 2019-07-31 22:16:17
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 688 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-07-05 07:19:04
合計ジャッジ時間 2,144 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 25 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

def bfs():
    if X == 0 and Y == 0:
        return True
        
    queue = deque([])
    queue.append((0, 0, 0))
    
    while len(queue) > 0:
        current_x, current_y, current_depth= queue.popleft()
        for move_x, move_y in [(-2, -1), (-2, 1), (-1, -2), (-1, 2), (1, -2), (1, 2), (2, -1), (2, 1)]:
            next_x, next_y = current_x + move_x, current_y + move_y
            if X == next_x and Y == next_y:
                return True
            if current_depth < 3:
                queue.append((next_x, next_y, current_depth + 1))
    
    return False

X, Y = map(int, input().split())

if bfs():
    print('YES')
else:
    print('NO')
0