結果

問題 No.3 ビットすごろく
ユーザー zyxwzyxw
提出日時 2020-10-24 17:46:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 38 ms / 5,000 ms
コード長 402 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 10,164 KB
最終ジャッジ日時 2023-09-14 01:53:07
合計ジャッジ時間 2,298 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,876 KB
testcase_01 AC 16 ms
7,788 KB
testcase_02 AC 16 ms
7,836 KB
testcase_03 AC 22 ms
8,592 KB
testcase_04 AC 18 ms
7,928 KB
testcase_05 AC 27 ms
9,140 KB
testcase_06 AC 21 ms
8,524 KB
testcase_07 AC 19 ms
8,264 KB
testcase_08 AC 25 ms
9,036 KB
testcase_09 AC 31 ms
9,456 KB
testcase_10 AC 34 ms
9,776 KB
testcase_11 AC 29 ms
9,376 KB
testcase_12 AC 28 ms
9,200 KB
testcase_13 AC 26 ms
8,280 KB
testcase_14 AC 33 ms
9,668 KB
testcase_15 AC 38 ms
10,012 KB
testcase_16 AC 36 ms
9,844 KB
testcase_17 AC 37 ms
10,112 KB
testcase_18 AC 20 ms
8,212 KB
testcase_19 AC 37 ms
10,164 KB
testcase_20 AC 18 ms
7,772 KB
testcase_21 AC 16 ms
7,948 KB
testcase_22 AC 33 ms
9,792 KB
testcase_23 AC 37 ms
10,104 KB
testcase_24 AC 38 ms
10,160 KB
testcase_25 AC 37 ms
10,072 KB
testcase_26 AC 15 ms
7,876 KB
testcase_27 AC 20 ms
8,288 KB
testcase_28 AC 35 ms
9,808 KB
testcase_29 AC 30 ms
9,400 KB
testcase_30 AC 16 ms
7,884 KB
testcase_31 AC 17 ms
7,824 KB
testcase_32 AC 29 ms
9,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
ri=[[] for i in range(N+1)]
for i in range(1,N):
    x=list(bin(i)).count("1")
    if 1<=i+x<=N:
        ri[i].append(i+x)
    if 1<=i-x<=N:
        ri[i].append(i-x)
ans=[0]*N
ans[0]=1
deque=[1]
while deque:
    y=deque.pop(0)
    for i in ri[y]:
        if ans[i-1]==0:
            ans[i-1]=ans[y-1]+1
            deque.append(i)
if ans[N-1]==0:
    print(-1)
else:
    print(ans[N-1])
0