結果

問題 No.1577 織姫と彦星2
ユーザー titiatitia
提出日時 2024-02-18 02:53:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 482 bytes
コンパイル時間 871 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 93,872 KB
最終ジャッジ日時 2024-02-18 02:53:34
合計ジャッジ時間 7,844 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 49 ms
53,460 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 43 ms
53,460 KB
testcase_05 AC 43 ms
64,388 KB
testcase_06 AC 40 ms
61,508 KB
testcase_07 AC 132 ms
86,352 KB
testcase_08 AC 63 ms
73,304 KB
testcase_09 AC 120 ms
93,872 KB
testcase_10 AC 54 ms
70,492 KB
testcase_11 AC 46 ms
64,560 KB
testcase_12 AC 71 ms
78,772 KB
testcase_13 AC 47 ms
69,896 KB
testcase_14 AC 75 ms
81,216 KB
testcase_15 AC 58 ms
71,788 KB
testcase_16 AC 113 ms
85,392 KB
testcase_17 AC 71 ms
77,056 KB
testcase_18 AC 40 ms
62,096 KB
testcase_19 AC 90 ms
82,932 KB
testcase_20 AC 85 ms
80,136 KB
testcase_21 AC 101 ms
85,340 KB
testcase_22 AC 94 ms
84,320 KB
testcase_23 AC 64 ms
72,724 KB
testcase_24 AC 89 ms
88,660 KB
testcase_25 AC 56 ms
69,256 KB
testcase_26 AC 63 ms
72,740 KB
testcase_27 AC 64 ms
80,712 KB
testcase_28 AC 91 ms
80,096 KB
testcase_29 AC 58 ms
74,756 KB
testcase_30 AC 65 ms
75,192 KB
testcase_31 AC 91 ms
83,892 KB
testcase_32 AC 43 ms
62,340 KB
testcase_33 AC 42 ms
62,352 KB
testcase_34 AC 58 ms
73,968 KB
testcase_35 AC 88 ms
82,836 KB
testcase_36 AC 89 ms
83,812 KB
testcase_37 AC 116 ms
93,088 KB
testcase_38 AC 107 ms
93,180 KB
testcase_39 AC 63 ms
73,412 KB
testcase_40 AC 59 ms
73,528 KB
testcase_41 AC 79 ms
85,168 KB
testcase_42 AC 58 ms
76,772 KB
testcase_43 AC 59 ms
76,652 KB
testcase_44 AC 45 ms
62,468 KB
testcase_45 AC 54 ms
68,924 KB
testcase_46 AC 47 ms
67,224 KB
testcase_47 AC 61 ms
81,744 KB
testcase_48 AC 52 ms
71,116 KB
testcase_49 AC 89 ms
74,792 KB
testcase_50 AC 57 ms
72,080 KB
testcase_51 AC 43 ms
64,156 KB
testcase_52 AC 88 ms
88,392 KB
testcase_53 AC 92 ms
89,460 KB
testcase_54 AC 57 ms
74,684 KB
testcase_55 AC 82 ms
87,400 KB
testcase_56 AC 58 ms
71,888 KB
testcase_57 AC 50 ms
66,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from collections import deque
N=int(input())
start,end=map(int,input().split())
S=list(map(int,input().split()))
S.append(end)
S.append(start)
SET=set(S)

DP=dict()
DP[start]=0
Q=deque([start])

while Q:
    x=Q.popleft()

    for i in range(32):
        y=x^(1<<i)
        if y in SET:
            if not(y in DP):
                DP[y]=DP[x]+1
                Q.append(y)

if end in DP:
    print(DP[end]-1)
else:
    print(-1)
            
0