結果

問題 No.1576 織姫と彦星
ユーザー boeboeMartinboeboeMartin
提出日時 2021-07-21 14:36:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 430 ms / 2,000 ms
コード長 1,058 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 87,024 KB
実行使用メモリ 77,992 KB
最終ジャッジ日時 2023-09-24 13:08:03
合計ジャッジ時間 13,631 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
71,456 KB
testcase_01 AC 90 ms
71,844 KB
testcase_02 AC 86 ms
71,604 KB
testcase_03 AC 86 ms
71,556 KB
testcase_04 AC 84 ms
71,752 KB
testcase_05 AC 84 ms
71,600 KB
testcase_06 AC 83 ms
71,752 KB
testcase_07 AC 138 ms
77,400 KB
testcase_08 AC 114 ms
77,448 KB
testcase_09 AC 96 ms
77,296 KB
testcase_10 AC 286 ms
77,764 KB
testcase_11 AC 98 ms
77,424 KB
testcase_12 AC 190 ms
77,828 KB
testcase_13 AC 197 ms
77,472 KB
testcase_14 AC 251 ms
77,804 KB
testcase_15 AC 234 ms
77,764 KB
testcase_16 AC 168 ms
77,512 KB
testcase_17 AC 214 ms
77,712 KB
testcase_18 AC 115 ms
77,512 KB
testcase_19 AC 141 ms
77,760 KB
testcase_20 AC 98 ms
77,492 KB
testcase_21 AC 226 ms
77,696 KB
testcase_22 AC 124 ms
77,336 KB
testcase_23 AC 98 ms
77,572 KB
testcase_24 AC 114 ms
77,408 KB
testcase_25 AC 215 ms
77,572 KB
testcase_26 AC 163 ms
77,624 KB
testcase_27 AC 98 ms
77,560 KB
testcase_28 AC 212 ms
77,696 KB
testcase_29 AC 161 ms
77,948 KB
testcase_30 AC 98 ms
76,212 KB
testcase_31 AC 161 ms
77,872 KB
testcase_32 AC 211 ms
77,768 KB
testcase_33 AC 403 ms
77,948 KB
testcase_34 AC 100 ms
77,528 KB
testcase_35 AC 193 ms
77,616 KB
testcase_36 AC 113 ms
77,648 KB
testcase_37 AC 430 ms
77,860 KB
testcase_38 AC 246 ms
77,836 KB
testcase_39 AC 207 ms
77,640 KB
testcase_40 AC 173 ms
77,764 KB
testcase_41 AC 193 ms
77,672 KB
testcase_42 AC 103 ms
77,388 KB
testcase_43 AC 116 ms
77,324 KB
testcase_44 AC 383 ms
77,688 KB
testcase_45 AC 149 ms
77,460 KB
testcase_46 AC 281 ms
77,816 KB
testcase_47 AC 101 ms
77,384 KB
testcase_48 AC 196 ms
77,584 KB
testcase_49 AC 188 ms
77,572 KB
testcase_50 AC 94 ms
77,368 KB
testcase_51 AC 95 ms
77,488 KB
testcase_52 AC 118 ms
77,636 KB
testcase_53 AC 264 ms
77,992 KB
testcase_54 AC 237 ms
77,788 KB
testcase_55 AC 250 ms
77,780 KB
testcase_56 AC 260 ms
77,836 KB
testcase_57 AC 99 ms
77,596 KB
testcase_58 AC 138 ms
77,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
# import time

def hmg_d(a, b):
    x = bin(a ^ b)
    cnt = 0
    for i in x:
        if i == "1":
            cnt += 1
        if cnt > 1:
            return False
    if cnt == 1:
        return True
    else:
        return False

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

# start_time = time.time()

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

stone_dict = {}
stone_dict[start] = 0
end_dict = {}
for i in stone:
    stone_dict[i] = 0
    end_dict[i] = 0
    if hmg_d(i, end):
        end_dict[i] = 1

queue = deque()
queue.append(start)

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

            # 終了条件
            if end_dict[i] == 1:
                print(stone_dict[i])
                # print(time.time() - start_time)
                exit()
            
            l.append(i)
    
    for i in l:
        stone.remove(i)

print(-1)
0