結果

問題 No.240 ナイト散歩
ユーザー rpy3cpp
提出日時 2015-07-10 22:35:52
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 705 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-10-07 20:48:55
合計ジャッジ時間 2,023 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

x, y = map(int, input().split())

def canmove(gx, gy):
    if gx == 0 and gy == 0:
        return True
    frontiers = [(0, 0)]
    visited = set()
    for i in range(3):
        new_frontiers = set()
        for x, y in frontiers:
            for dx, dy in [(-2, -1), (-2, 1), (-1, -2), (-1, 2), (1, -2), (1, 2), (2, -1), (2, 1)]:
                nx, ny = x + dx, y + dy
                if nx == gx and ny == gy:
                    return True
                if (nx, ny) in visited:
                    continue
                visited.add((nx, ny))
                new_frontiers.add((nx, ny))
        frontiers = new_frontiers
    return False

if canmove(x, y):
    print('YES')
else:
    print('NO')
0