結果

問題 No.1576 織姫と彦星
ユーザー boeboeMartinboeboeMartin
提出日時 2021-07-20 18:42:58
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 748 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 80,636 KB
最終ジャッジ日時 2023-09-24 12:52:12
合計ジャッジ時間 34,302 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
71,748 KB
testcase_01 AC 88 ms
71,588 KB
testcase_02 AC 86 ms
71,596 KB
testcase_03 AC 91 ms
71,444 KB
testcase_04 AC 90 ms
71,468 KB
testcase_05 AC 89 ms
71,628 KB
testcase_06 AC 92 ms
76,436 KB
testcase_07 AC 364 ms
78,500 KB
testcase_08 AC 176 ms
78,624 KB
testcase_09 AC 126 ms
78,124 KB
testcase_10 AC 1,067 ms
79,804 KB
testcase_11 AC 121 ms
77,480 KB
testcase_12 AC 622 ms
78,772 KB
testcase_13 AC 571 ms
79,408 KB
testcase_14 AC 998 ms
79,704 KB
testcase_15 AC 837 ms
78,684 KB
testcase_16 AC 435 ms
78,424 KB
testcase_17 AC 753 ms
78,732 KB
testcase_18 AC 240 ms
79,448 KB
testcase_19 AC 472 ms
78,652 KB
testcase_20 AC 129 ms
78,176 KB
testcase_21 AC 792 ms
79,696 KB
testcase_22 AC 247 ms
78,468 KB
testcase_23 AC 143 ms
78,248 KB
testcase_24 AC 210 ms
78,752 KB
testcase_25 AC 623 ms
78,536 KB
testcase_26 AC 628 ms
78,688 KB
testcase_27 AC 123 ms
78,064 KB
testcase_28 AC 649 ms
78,780 KB
testcase_29 AC 592 ms
78,796 KB
testcase_30 AC 108 ms
76,688 KB
testcase_31 AC 473 ms
79,244 KB
testcase_32 AC 728 ms
80,636 KB
testcase_33 AC 1,864 ms
79,016 KB
testcase_34 AC 125 ms
77,688 KB
testcase_35 AC 652 ms
78,952 KB
testcase_36 AC 221 ms
78,368 KB
testcase_37 AC 1,933 ms
79,324 KB
testcase_38 AC 825 ms
78,684 KB
testcase_39 AC 695 ms
78,856 KB
testcase_40 AC 535 ms
78,424 KB
testcase_41 AC 617 ms
78,852 KB
testcase_42 AC 144 ms
78,352 KB
testcase_43 AC 235 ms
79,544 KB
testcase_44 TLE -
testcase_45 AC 365 ms
78,388 KB
testcase_46 AC 1,326 ms
80,076 KB
testcase_47 AC 127 ms
78,184 KB
testcase_48 AC 824 ms
78,612 KB
testcase_49 AC 675 ms
78,644 KB
testcase_50 AC 127 ms
78,040 KB
testcase_51 AC 128 ms
78,160 KB
testcase_52 AC 207 ms
78,336 KB
testcase_53 AC 1,442 ms
78,720 KB
testcase_54 AC 727 ms
78,744 KB
testcase_55 AC 732 ms
78,584 KB
testcase_56 AC 775 ms
78,592 KB
testcase_57 AC 122 ms
77,904 KB
testcase_58 AC 306 ms
78,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
from collections import deque

def hmg_d(a, b):
    count = Counter(list(bin(a ^ b)))
    if count["1"] == 1:
        return True
    else:
        return False

n = int(input())
start, end = map(int,input().split())
stone = list(map(int,input().split()))

if hmg_d(start, end):
    print(0)
    exit()

stone_dict = {}
stone_dict[start] = 0
for i in stone:
    stone_dict[i] = 0

queue = deque()
queue.append(start)

while queue:
    v = queue.popleft()
    for i in stone:
        if hmg_d(v, i):
            if stone_dict[i] == 0:
                stone_dict[i] = stone_dict[v] + 1
                queue.append(i)
            if hmg_d(i, end):
                print(stone_dict[i])
                exit()

print(-1)
0