結果

問題 No.3 ビットすごろく
ユーザー goto_isyukugoto_isyuku
提出日時 2017-05-26 19:51:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 823 ms / 5,000 ms
コード長 508 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 10,896 KB
実行使用メモリ 8,868 KB
最終ジャッジ日時 2023-09-14 00:44:36
合計ジャッジ時間 11,976 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,552 KB
testcase_01 AC 17 ms
8,416 KB
testcase_02 AC 17 ms
8,564 KB
testcase_03 AC 69 ms
8,420 KB
testcase_04 AC 24 ms
8,444 KB
testcase_05 AC 241 ms
8,632 KB
testcase_06 AC 78 ms
8,496 KB
testcase_07 AC 39 ms
8,668 KB
testcase_08 AC 163 ms
8,728 KB
testcase_09 AC 394 ms
8,632 KB
testcase_10 AC 549 ms
8,684 KB
testcase_11 AC 325 ms
8,684 KB
testcase_12 AC 226 ms
8,716 KB
testcase_13 AC 52 ms
8,536 KB
testcase_14 AC 505 ms
8,796 KB
testcase_15 AC 783 ms
8,708 KB
testcase_16 AC 682 ms
8,776 KB
testcase_17 AC 759 ms
8,728 KB
testcase_18 AC 44 ms
8,460 KB
testcase_19 AC 823 ms
8,672 KB
testcase_20 AC 20 ms
8,512 KB
testcase_21 AC 18 ms
8,636 KB
testcase_22 AC 531 ms
8,648 KB
testcase_23 AC 791 ms
8,676 KB
testcase_24 AC 807 ms
8,736 KB
testcase_25 AC 789 ms
8,868 KB
testcase_26 AC 17 ms
8,416 KB
testcase_27 AC 58 ms
8,548 KB
testcase_28 AC 644 ms
8,776 KB
testcase_29 AC 337 ms
8,684 KB
testcase_30 AC 17 ms
8,372 KB
testcase_31 AC 18 ms
8,540 KB
testcase_32 AC 286 ms
8,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections as cols

n = int(input())
ans = -1

l = cols.deque()

l.append((1, 1))

s = []

def bitcount(n):
    return bin(n).count("1")

while True:
    try:
        a, b = l.popleft()
    except:
        break
    if a in s or a < 1 or a > n:
        pass
    else:
        if a == n:
            ans = b
            break
        else:
            s.append(a)
    
            d = bitcount(a)
        
            l.append((a - d, b + 1))
            l.append((a + d, b + 1))
    
    

print(ans)
0