結果

問題 No.3 ビットすごろく
ユーザー るさるさ
提出日時 2018-06-03 17:05:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 189 ms / 5,000 ms
コード長 542 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 10,976 KB
実行使用メモリ 9,092 KB
最終ジャッジ日時 2023-09-14 01:01:40
合計ジャッジ時間 4,737 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,504 KB
testcase_01 AC 18 ms
8,412 KB
testcase_02 AC 17 ms
8,528 KB
testcase_03 AC 49 ms
8,524 KB
testcase_04 AC 25 ms
8,500 KB
testcase_05 AC 106 ms
8,784 KB
testcase_06 AC 55 ms
8,540 KB
testcase_07 AC 36 ms
8,384 KB
testcase_08 AC 87 ms
8,592 KB
testcase_09 AC 129 ms
8,776 KB
testcase_10 AC 154 ms
8,948 KB
testcase_11 AC 121 ms
8,852 KB
testcase_12 AC 100 ms
8,752 KB
testcase_13 AC 39 ms
8,584 KB
testcase_14 AC 151 ms
8,812 KB
testcase_15 AC 187 ms
9,024 KB
testcase_16 AC 174 ms
8,928 KB
testcase_17 AC 186 ms
8,908 KB
testcase_18 AC 38 ms
8,468 KB
testcase_19 AC 186 ms
8,956 KB
testcase_20 AC 22 ms
8,524 KB
testcase_21 AC 18 ms
8,344 KB
testcase_22 AC 152 ms
8,936 KB
testcase_23 AC 189 ms
9,092 KB
testcase_24 AC 187 ms
8,984 KB
testcase_25 AC 186 ms
8,952 KB
testcase_26 AC 18 ms
8,392 KB
testcase_27 AC 47 ms
8,512 KB
testcase_28 AC 171 ms
8,872 KB
testcase_29 AC 123 ms
8,776 KB
testcase_30 AC 19 ms
8,356 KB
testcase_31 AC 19 ms
8,336 KB
testcase_32 AC 117 ms
8,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import copy
n=int(input())
field=[100000 for i in range(n)]
field[0]=1

def bitcnt(x):
    cnt=0
    while True:
        cnt+=x&1
        x=x>>1
        if x==0:
            break
    return cnt
while True:
    fc=copy(field)
    for i in range(n):
        cnt=bitcnt(i+1)
        if i-cnt>=0:
            field[i-cnt]=min([field[i]+1,field[i-cnt]])
        if i+cnt<n:
            field[i+cnt]=min([field[i]+1,field[i+cnt]])
    if fc==field:
        break
    
if field[n-1]==100000:
    print(-1)
else:
    print(field[n-1])
    
0