結果

問題 No.1577 織姫と彦星2
ユーザー kitatike55kitatike55
提出日時 2021-07-08 23:25:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 428 ms / 2,000 ms
コード長 1,104 bytes
コンパイル時間 81 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 18,548 KB
最終ジャッジ日時 2023-09-14 05:39:23
合計ジャッジ時間 9,484 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,620 KB
testcase_01 AC 17 ms
8,688 KB
testcase_02 AC 18 ms
8,624 KB
testcase_03 AC 18 ms
8,616 KB
testcase_04 AC 18 ms
8,644 KB
testcase_05 AC 25 ms
10,428 KB
testcase_06 AC 21 ms
9,100 KB
testcase_07 AC 59 ms
15,000 KB
testcase_08 AC 128 ms
11,572 KB
testcase_09 AC 237 ms
17,368 KB
testcase_10 AC 56 ms
11,124 KB
testcase_11 AC 32 ms
8,992 KB
testcase_12 AC 130 ms
13,884 KB
testcase_13 AC 34 ms
10,620 KB
testcase_14 AC 194 ms
14,340 KB
testcase_15 AC 109 ms
10,764 KB
testcase_16 AC 229 ms
17,244 KB
testcase_17 AC 132 ms
13,504 KB
testcase_18 AC 20 ms
8,720 KB
testcase_19 AC 272 ms
17,248 KB
testcase_20 AC 251 ms
16,068 KB
testcase_21 AC 322 ms
17,360 KB
testcase_22 AC 226 ms
17,200 KB
testcase_23 AC 128 ms
11,380 KB
testcase_24 AC 199 ms
15,268 KB
testcase_25 AC 72 ms
10,832 KB
testcase_26 AC 129 ms
11,380 KB
testcase_27 AC 69 ms
14,180 KB
testcase_28 AC 179 ms
14,388 KB
testcase_29 AC 70 ms
13,252 KB
testcase_30 AC 128 ms
13,776 KB
testcase_31 AC 223 ms
17,264 KB
testcase_32 AC 21 ms
8,796 KB
testcase_33 AC 23 ms
8,836 KB
testcase_34 AC 94 ms
13,324 KB
testcase_35 AC 223 ms
17,220 KB
testcase_36 AC 266 ms
17,404 KB
testcase_37 AC 428 ms
18,548 KB
testcase_38 AC 175 ms
15,560 KB
testcase_39 AC 102 ms
11,512 KB
testcase_40 AC 108 ms
11,592 KB
testcase_41 AC 88 ms
15,980 KB
testcase_42 AC 63 ms
14,104 KB
testcase_43 AC 75 ms
14,184 KB
testcase_44 AC 24 ms
8,792 KB
testcase_45 AC 66 ms
10,480 KB
testcase_46 AC 37 ms
9,960 KB
testcase_47 AC 57 ms
15,704 KB
testcase_48 AC 47 ms
10,888 KB
testcase_49 AC 105 ms
13,496 KB
testcase_50 AC 49 ms
10,648 KB
testcase_51 AC 21 ms
9,020 KB
testcase_52 AC 228 ms
17,512 KB
testcase_53 AC 219 ms
15,476 KB
testcase_54 AC 79 ms
13,888 KB
testcase_55 AC 207 ms
15,548 KB
testcase_56 AC 111 ms
11,204 KB
testcase_57 AC 39 ms
9,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
start,end = map(int,input().split())
stone = list(map(int,input().split()))
stoneMax = max(stone)
maxLen = int(len(bin(stoneMax)[2:]))

setStone= set(stone)
avoidStone = set()
from collections import deque
def bfs(u):
    queue = deque([u,0])
    while queue:
        v = queue.popleft()
        dis = queue.popleft()
        h = serchHam(v)
        if end in h:
            print(dis)
            exit()
        # stoneS = stone.copy()
        for i in h:
            # if i in setStone:
            queue.append(i)
            queue.append(dis+1)
                # stone.remove(i)
    print(-1)
    exit() 
      
def serchHam(a):
    h=[]
    abin = bin(a+2**maxLen)[2:]
    for i in range(1,maxLen+1):
        if abin[i] == '0':
            hh = 2**(maxLen-i)+a
        else:
            hh = a-2**(maxLen-i)
        if hh == end:
            h.append(hh)
            return h
        if hh in setStone:
            if hh in avoidStone:
                continue
            else:
                h.append(hh)
                avoidStone.add(hh)
    # print(h)
    return h

bfs(start)
0