結果

問題 No.1576 織姫と彦星
ユーザー ygd.ygd.
提出日時 2021-06-29 23:59:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 893 bytes
コンパイル時間 548 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 77,720 KB
最終ジャッジ日時 2023-09-08 09:29:53
合計ジャッジ時間 10,011 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
71,684 KB
testcase_01 AC 100 ms
71,792 KB
testcase_02 AC 97 ms
71,904 KB
testcase_03 AC 97 ms
71,936 KB
testcase_04 AC 97 ms
71,812 KB
testcase_05 AC 98 ms
71,656 KB
testcase_06 AC 97 ms
71,704 KB
testcase_07 AC 112 ms
77,640 KB
testcase_08 AC 108 ms
77,268 KB
testcase_09 AC 103 ms
76,852 KB
testcase_10 AC 117 ms
77,628 KB
testcase_11 AC 102 ms
76,536 KB
testcase_12 AC 111 ms
77,300 KB
testcase_13 AC 116 ms
77,416 KB
testcase_14 AC 116 ms
77,504 KB
testcase_15 AC 114 ms
77,272 KB
testcase_16 AC 114 ms
77,484 KB
testcase_17 AC 113 ms
77,264 KB
testcase_18 AC 105 ms
77,580 KB
testcase_19 AC 106 ms
77,272 KB
testcase_20 AC 112 ms
77,296 KB
testcase_21 AC 112 ms
77,556 KB
testcase_22 AC 113 ms
77,488 KB
testcase_23 AC 107 ms
77,616 KB
testcase_24 AC 106 ms
77,440 KB
testcase_25 AC 117 ms
77,396 KB
testcase_26 AC 108 ms
77,536 KB
testcase_27 AC 103 ms
76,732 KB
testcase_28 AC 114 ms
77,424 KB
testcase_29 AC 110 ms
77,508 KB
testcase_30 AC 97 ms
71,916 KB
testcase_31 AC 107 ms
77,468 KB
testcase_32 AC 114 ms
77,484 KB
testcase_33 AC 123 ms
77,720 KB
testcase_34 AC 104 ms
76,848 KB
testcase_35 AC 111 ms
77,412 KB
testcase_36 AC 106 ms
76,760 KB
testcase_37 AC 125 ms
77,492 KB
testcase_38 AC 116 ms
77,300 KB
testcase_39 AC 112 ms
77,508 KB
testcase_40 AC 109 ms
77,592 KB
testcase_41 AC 110 ms
77,404 KB
testcase_42 AC 104 ms
76,924 KB
testcase_43 AC 105 ms
77,432 KB
testcase_44 AC 122 ms
77,296 KB
testcase_45 AC 108 ms
77,108 KB
testcase_46 AC 116 ms
77,144 KB
testcase_47 AC 105 ms
77,632 KB
testcase_48 AC 109 ms
77,268 KB
testcase_49 AC 111 ms
77,600 KB
testcase_50 AC 104 ms
76,852 KB
testcase_51 AC 103 ms
77,112 KB
testcase_52 AC 113 ms
77,312 KB
testcase_53 AC 112 ms
77,536 KB
testcase_54 AC 114 ms
77,604 KB
testcase_55 AC 115 ms
77,492 KB
testcase_56 AC 120 ms
77,476 KB
testcase_57 AC 103 ms
76,800 KB
testcase_58 AC 105 ms
77,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0