結果
| 問題 |
No.1576 織姫と彦星
|
| ユーザー |
|
| 提出日時 | 2021-06-18 23:50:31 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 44 ms / 2,000 ms |
| コード長 | 777 bytes |
| コンパイル時間 | 172 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 11,776 KB |
| 最終ジャッジ日時 | 2024-06-22 22:13:08 |
| 合計ジャッジ時間 | 4,102 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 54 |
ソースコード
import random
import queue
def solve(start, end, stones):
stone_set = set(stones)
checked_set = set()
que = queue.Queue()
que.put((start, 0))
while not que.empty():
current, distance = que.get()
next_distance = distance + 1
for i in range(31):
candidate = current ^ (1<<i)
if candidate == end:
return next_distance - 1
if candidate in stone_set and candidate not in checked_set:
checked_set.add(candidate)
que.put((candidate, next_distance))
return -1
if __name__ == '__main__':
N = int(input())
start, end = list(map(int, input().split()))
stones = list(map(int, input().split()))
print(solve(start, end, stones))