結果
問題 |
No.1576 織姫と彦星
|
ユーザー |
![]() |
提出日時 | 2021-06-29 23:59:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 70 ms / 2,000 ms |
コード長 | 893 bytes |
コンパイル時間 | 321 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 63,744 KB |
最終ジャッジ日時 | 2024-06-26 02:33:58 |
合計ジャッジ時間 | 5,057 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 54 |
ソースコード
from collections import deque def main(): twos = [1] for i in range(40): twos.append(twos[-1]*2) twos = set(twos) #print(twos) N = int(input()); INF = float("inf") N += 2 start,end = map(int,input().split()) stone = [start] + list(map(int,input().split())) + [end] G = [[] for _ in range(N)] for i in range(N): for j in range(i+1,N): k = stone[i]^stone[j] #print(i,j,k) if k in twos: G[i].append(j) G[j].append(i) #print(G) D = [-1]*N Q = deque([]) Q.append(0) D[0] = 0 while Q: v = Q.popleft() for u in G[v]: if D[u] != -1: continue D[u] = D[v] + 1 Q.append(u) #print(D,N) if D[N-1] == -1: print(-1) else: print(D[N-1] - 1) if __name__ == '__main__': main()