結果
| 問題 |
No.1577 織姫と彦星2
|
| ユーザー |
y05h1k1ng
|
| 提出日時 | 2021-07-01 12:48:49 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 639 bytes |
| コンパイル時間 | 102 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 21,856 KB |
| 最終ジャッジ日時 | 2024-06-28 01:53:39 |
| 合計ジャッジ時間 | 4,878 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 2 TLE * 1 -- * 50 |
ソースコード
from collections import deque
def hamming_distance(a: int, b: int) -> int:
x = a ^ b
return bin(x)[2:].count("1")
n = int(input())
start, end = map(int, input().split(" "))
stones = list(map(int, input().split(" ")))
visited = [False] * n
que = deque([])
que.append((0, start))
while len(que):
cnt, now = que.popleft()
if hamming_distance(now, end) == 1:
print(cnt)
break
for i in range(n):
stone = stones[i]
if visited[i]:
continue
if hamming_distance(now, stone) == 1:
visited[i] = True
que.append((cnt+1, stone))
else:
print(-1)
y05h1k1ng