結果

問題 No.3 ビットすごろく
ユーザー momike1341momike1341
提出日時 2020-03-26 21:27:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 832 ms / 5,000 ms
コード長 729 bytes
コンパイル時間 115 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 10,184 KB
最終ジャッジ日時 2023-09-14 01:40:25
合計ジャッジ時間 11,977 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,820 KB
testcase_01 AC 16 ms
7,836 KB
testcase_02 AC 16 ms
7,812 KB
testcase_03 AC 74 ms
8,616 KB
testcase_04 AC 23 ms
8,408 KB
testcase_05 AC 256 ms
9,216 KB
testcase_06 AC 87 ms
8,696 KB
testcase_07 AC 41 ms
8,648 KB
testcase_08 AC 172 ms
8,964 KB
testcase_09 AC 408 ms
9,636 KB
testcase_10 AC 570 ms
9,668 KB
testcase_11 AC 348 ms
9,592 KB
testcase_12 AC 243 ms
9,164 KB
testcase_13 AC 58 ms
8,520 KB
testcase_14 AC 536 ms
9,596 KB
testcase_15 AC 806 ms
10,184 KB
testcase_16 AC 704 ms
9,948 KB
testcase_17 AC 779 ms
10,064 KB
testcase_18 AC 47 ms
8,468 KB
testcase_19 AC 832 ms
9,980 KB
testcase_20 AC 20 ms
8,340 KB
testcase_21 AC 16 ms
7,804 KB
testcase_22 AC 553 ms
9,784 KB
testcase_23 AC 824 ms
10,108 KB
testcase_24 AC 823 ms
10,120 KB
testcase_25 AC 806 ms
10,148 KB
testcase_26 AC 16 ms
7,812 KB
testcase_27 AC 65 ms
8,744 KB
testcase_28 AC 674 ms
10,064 KB
testcase_29 AC 361 ms
9,408 KB
testcase_30 AC 16 ms
7,940 KB
testcase_31 AC 17 ms
7,872 KB
testcase_32 AC 311 ms
9,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def can_go(n):
    return sum(map(int,list(n)))

N=int(input())

m=dict(zip(range(1,N+1),list(map(format,range(1,N+1),N*"b"))))
queue=[1]
Visited=[]#訪問済み
cost=[float("inf") for i in range(N)]
cost[0]=1
next_target=[]
goal=N

##print(m,goal)

while(1):
    if len(queue)==0:
        break
    target=queue[0]
    if target==goal:
        break
    next_target=[target+can_go(m[target]),target-can_go(m[target])]
    for i in next_target:
        if 1<=i and i<=N and not i in queue and not i in Visited:
            queue.append(i)
            cost[i-1]=cost[target-1]+1 
            
    queue.pop(0)
    Visited.append(target)
##    print(queue,cost)

if cost[-1]!=float("inf"):
    print(cost[N-1])
else :
    print(-1)
0