結果

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

ソースコード

diff #

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

X, Y = map(int, input().split())

def dfs(x, y, X, Y, i):
    if i == 3+1:
        return False
    if x == X and y == Y:
        return True

    if dfs(x-2, y-1, X, Y, i+1): return True
    if dfs(x-2, y+1, X, Y, i+1): return True
    if dfs(x-1, y-2, X, Y, i+1): return True
    if dfs(x-1, y+2, X, Y, i+1): return True
    if dfs(x+1, y-2, X, Y, i+1): return True
    if dfs(x+1, y+2, X, Y, i+1): return True
    if dfs(x+2, y-1, X, Y, i+1): return True
    if dfs(x+2, y+1, X, Y, i+1): return True

    return False


print('YES' if dfs(0,0,X,Y,0) else 'NO')

0