結果

問題 No.240 ナイト散歩
コンテスト
ユーザー leno
提出日時 2017-08-29 21:38:48
言語 Python3
(3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 24 ms / 2,000 ms
+ 886µs
コード長 898 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 786 ms
コンパイル使用メモリ 14,848 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2026-10-28 17:20:55
合計ジャッジ時間 2,437 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import copy


def bfs(x, y):
    queue = [[0, 0]]
    cnt = 0
    while queue:
        stack = copy.deepcopy(queue)
        queue.clear()
        if cnt > 3:
            return False
        cnt += 1
        while stack:
            tmp = stack.pop(0)
            if tmp[0] == x and tmp[1] == y:
                return True
            queue = [
                [tmp[0] - 2, tmp[1] - 1],
                [tmp[0] - 2, tmp[1] + 1],
                [tmp[0] - 1, tmp[1] - 2],
                [tmp[0] - 1, tmp[1] + 2],
                [tmp[0] + 1, tmp[1] - 2],
                [tmp[0] + 1, tmp[1] + 2],
                [tmp[0] + 2, tmp[1] - 1],
                [tmp[0] + 2, tmp[1] + 1]
            ] + queue
    return False


if __name__ == '__main__':
    X, Y = [int(i) for i in input().split()]
    if bfs(X, Y):
        print('YES')
    else:
        print('NO')
0