結果

問題 No.240 ナイト散歩
コンテスト
ユーザー lam6er
提出日時 2025-03-31 17:31:34
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 37 ms / 2,000 ms
+ 533µs
コード長 905 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 189 ms
コンパイル使用メモリ 64,304 KB
実行使用メモリ 53,636 KB
最終ジャッジ日時 2026-10-28 17:35:08
合計ジャッジ時間 3,177 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
from collections import deque

# Generate all reachable positions up to 3 steps
directions = [
    (2, 1), (2, -1), (-2, 1), (-2, -1),
    (1, 2), (1, -2), (-1, 2), (-1, -2)
]

reachable = set()
visited = set()

queue = deque()
queue.append((0, 0, 0))
visited.add((0, 0))
reachable.add((0, 0))

while queue:
    x, y, steps = queue.popleft()
    if steps < 3:
        for dx, dy in directions:
            nx = x + dx
            ny = y + dy
            if (nx, ny) not in visited:
                visited.add((nx, ny))
                queue.append((nx, ny, steps + 1))
                reachable.add((nx, ny))

# Read input
X, Y = map(int, sys.stdin.readline().split())

if X == 0 and Y == 0:
    print("YES")
else:
    manhattan = abs(X) + abs(Y)
    if manhattan > 9:
        print("NO")
    else:
        if (X, Y) in reachable:
            print("YES")
        else:
            print("NO")
0