結果
| 問題 | No.1577 織姫と彦星2 |
| ユーザー |
|
| 提出日時 | 2021-07-08 22:33:52 |
| 言語 | Python3 (3.14.3 + numpy 2.4.4 + scipy 1.17.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 821 bytes |
| 記録 | |
| コンパイル時間 | 458 ms |
| コンパイル使用メモリ | 20,704 KB |
| 実行使用メモリ | 34,484 KB |
| 最終ジャッジ日時 | 2026-03-22 14:12:15 |
| 合計ジャッジ時間 | 140,549 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 8 TLE * 45 |
ソースコード
n = int(input())
start,end = map(int,input().split())
stone = list(map(int,input().split()))
stoneMax = max(stone)
maxLen = int(len(bin(stoneMax)[2:]))
from collections import deque
def bfs(u):
queue = deque([u,0])
while queue:
v = queue.popleft()
dis = queue.popleft()
h = serchHam(v)
if end in h:
print(dis)
exit()
stoneS = stone.copy()
for i in stoneS:
if i in h:
queue.append(i)
queue.append(dis+1)
stone.remove(i)
print(-1)
exit()
def serchHam(a):
h=[]
abin = bin(a+2**maxLen)[2:]
for i in range(1,maxLen+1):
if abin[i] == '0':
h.append(2**(maxLen-i)+a)
else:
h.append(a-2**(maxLen-i))
return h
bfs(start)