結果

問題 No.240 ナイト散歩
ユーザー kichirb3kichirb3
提出日時 2018-03-17 02:30:36
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 849 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 8,708 KB
最終ジャッジ日時 2023-08-24 16:42:25
合計ジャッジ時間 2,937 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,548 KB
testcase_01 AC 19 ms
8,676 KB
testcase_02 AC 19 ms
8,488 KB
testcase_03 AC 19 ms
8,604 KB
testcase_04 AC 18 ms
8,500 KB
testcase_05 AC 19 ms
8,580 KB
testcase_06 AC 19 ms
8,684 KB
testcase_07 AC 18 ms
8,548 KB
testcase_08 AC 19 ms
8,688 KB
testcase_09 AC 19 ms
8,696 KB
testcase_10 AC 19 ms
8,604 KB
testcase_11 AC 19 ms
8,700 KB
testcase_12 AC 20 ms
8,508 KB
testcase_13 AC 19 ms
8,628 KB
testcase_14 AC 20 ms
8,708 KB
testcase_15 AC 20 ms
8,692 KB
testcase_16 AC 18 ms
8,508 KB
testcase_17 AC 19 ms
8,596 KB
testcase_18 AC 20 ms
8,540 KB
testcase_19 AC 19 ms
8,628 KB
testcase_20 AC 20 ms
8,520 KB
testcase_21 AC 19 ms
8,580 KB
testcase_22 AC 19 ms
8,504 KB
testcase_23 AC 19 ms
8,592 KB
testcase_24 AC 19 ms
8,552 KB
testcase_25 AC 20 ms
8,648 KB
testcase_26 AC 19 ms
8,652 KB
testcase_27 AC 18 ms
8,592 KB
testcase_28 AC 20 ms
8,576 KB
testcase_29 AC 19 ms
8,700 KB
testcase_30 AC 19 ms
8,668 KB
testcase_31 AC 19 ms
8,692 KB
testcase_32 AC 19 ms
8,552 KB
testcase_33 AC 19 ms
8,556 KB
権限があれば一括ダウンロードができます

ソースコード

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