結果
| 問題 |
No.240 ナイト散歩
|
| ユーザー |
はむ吉🐹
|
| 提出日時 | 2016-03-01 19:56:59 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 30 ms / 2,000 ms |
| コード長 | 1,013 bytes |
| コンパイル時間 | 305 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-10-07 21:22:04 |
| 合計ジャッジ時間 | 2,205 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import collections
DELTAS = [(-2, -1), (-2, 1), (-1, -2), (-1, 2),
(1, -2), (1, 2), (2, -1), (2, 1)]
INF = 2 ** 16 - 1
LIMIT = 3
def breadth_first_search(goal):
start = (0, 0)
dist = collections.defaultdict(lambda: INF)
dist[start] = 0
queue = collections.deque()
queue.append(start)
while queue:
(x0, y0) = queue.popleft()
if (x0, y0) == goal:
break
for dx, dy in DELTAS:
(x, y) = (x0 + dx, y0 + dy)
if dist[(x, y)] == INF:
dist[(x, y)] = dist[(x0, y0)] + 1
queue.append((x, y))
return dist[goal]
def judge(goal):
if goal == (0, 0):
return True
elif sum(map(abs, goal)) > 10:
return False
else:
return breadth_first_search(goal) <= LIMIT
def main():
if judge(tuple(map(int, input().split()))):
print("YES")
else:
print("NO")
if __name__ == '__main__':
main()
はむ吉🐹