結果
問題 | No.240 ナイト散歩 |
ユーザー |
![]() |
提出日時 | 2016-06-02 03:45:01 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 739 bytes |
コンパイル時間 | 221 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-10-07 21:25:41 |
合計ジャッジ時間 | 2,268 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
GOAL = tuple(map(int, input().split()))move = [(-2, -1),(-2, 1),(-1, -2),(-1, 2),(1, -2),(1, 2),(2, -1),(2, 1)]class Knight:def __init__(self, state, count):self.state = stateself.count = countdef dfs(goal):visited = []stack = [Knight((0, 0), 0)]while stack:a = stack.pop(0)if a.count > 3:continueif a.state == goal:return 'YES'x, y = a.staten = a.count + 1for j, k in move:v = (x+j, y+k)if v in visited:continuec = Knight(v, n)stack.append(c)visited.append(v)return 'NO'if __name__ == '__main__':print(dfs(GOAL))