結果

問題 No.1576 織姫と彦星
ユーザー boeboeMartinboeboeMartin
提出日時 2021-07-20 19:04:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 880 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 86,988 KB
実行使用メモリ 79,884 KB
最終ジャッジ日時 2023-09-24 12:53:18
合計ジャッジ時間 24,644 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
71,480 KB
testcase_01 AC 86 ms
71,420 KB
testcase_02 AC 87 ms
71,608 KB
testcase_03 AC 89 ms
71,348 KB
testcase_04 AC 87 ms
71,652 KB
testcase_05 AC 87 ms
71,448 KB
testcase_06 AC 91 ms
76,520 KB
testcase_07 AC 257 ms
78,356 KB
testcase_08 AC 165 ms
78,376 KB
testcase_09 AC 118 ms
78,008 KB
testcase_10 AC 755 ms
79,588 KB
testcase_11 AC 114 ms
77,556 KB
testcase_12 AC 473 ms
78,776 KB
testcase_13 AC 484 ms
78,408 KB
testcase_14 AC 672 ms
79,048 KB
testcase_15 AC 631 ms
79,668 KB
testcase_16 AC 416 ms
78,384 KB
testcase_17 AC 591 ms
78,784 KB
testcase_18 AC 192 ms
78,340 KB
testcase_19 AC 302 ms
78,728 KB
testcase_20 AC 123 ms
77,940 KB
testcase_21 AC 578 ms
79,420 KB
testcase_22 AC 217 ms
78,460 KB
testcase_23 AC 135 ms
78,096 KB
testcase_24 AC 176 ms
78,304 KB
testcase_25 AC 537 ms
78,712 KB
testcase_26 AC 355 ms
78,728 KB
testcase_27 AC 118 ms
77,560 KB
testcase_28 AC 508 ms
79,884 KB
testcase_29 AC 378 ms
78,540 KB
testcase_30 AC 97 ms
76,640 KB
testcase_31 AC 343 ms
78,708 KB
testcase_32 AC 536 ms
79,056 KB
testcase_33 AC 1,163 ms
78,900 KB
testcase_34 AC 117 ms
77,860 KB
testcase_35 AC 452 ms
78,692 KB
testcase_36 AC 171 ms
78,472 KB
testcase_37 AC 1,287 ms
78,888 KB
testcase_38 AC 655 ms
78,760 KB
testcase_39 AC 521 ms
78,560 KB
testcase_40 AC 375 ms
79,468 KB
testcase_41 AC 436 ms
78,592 KB
testcase_42 AC 132 ms
78,040 KB
testcase_43 AC 200 ms
78,572 KB
testcase_44 AC 1,202 ms
78,712 KB
testcase_45 AC 302 ms
78,268 KB
testcase_46 AC 780 ms
78,756 KB
testcase_47 AC 125 ms
77,800 KB
testcase_48 AC 490 ms
78,688 KB
testcase_49 AC 460 ms
78,588 KB
testcase_50 AC 124 ms
78,256 KB
testcase_51 AC 131 ms
77,972 KB
testcase_52 AC 200 ms
78,344 KB
testcase_53 AC 792 ms
78,780 KB
testcase_54 AC 616 ms
78,828 KB
testcase_55 AC 635 ms
78,628 KB
testcase_56 AC 727 ms
78,700 KB
testcase_57 AC 116 ms
77,532 KB
testcase_58 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
from collections import deque
# import time
# start_time = time.time()

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])
                # print(time.time() - start_time)
                exit()
            
            stone.remove(i)

print(-1)
0