結果

問題 No.240 ナイト散歩
ユーザー kichirb3
提出日時 2018-03-17 02:30:36
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 849 bytes
コンパイル時間 129 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-12-23 00:50:54
合計ジャッジ時間 2,518 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
"""
No.240 ナイト散歩
https://yukicoder.me/problems/no/240

"""
import sys
from sys import stdin
from collections import deque
input = stdin.readline


def solve(gx, gy, step=3):
    #  ナイトが1歩で動ける座標
    dx = [-2, -2, -1, -1,  1, 1,  2, 2]
    dy = [-1,  1, -2,  2, -2, 2, -1, 1]

    cx, cy = 0, 0
    Q = deque()
    Q.append([cx, cy, step])

    while Q:
        cx, cy, step = Q.popleft()
        if step > 0:
            for i in range(len(dx)):
                nx = cx + dx[i]
                ny = cy + dy[i]
                if nx == gx and ny == gy:
                    return 'YES'
                Q.append([nx, ny, step - 1])
    return 'NO'


def main(args):
    gx, gy = map(int, input().split())
    ans = solve(gx, gy)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
0