結果

問題 No.3 ビットすごろく
ユーザー syuki791syuki791
提出日時 2019-02-03 11:01:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 730 bytes
コンパイル時間 1,938 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 8,940 KB
最終ジャッジ日時 2023-08-22 06:02:02
合計ジャッジ時間 2,502 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,612 KB
testcase_01 AC 19 ms
8,552 KB
testcase_02 AC 20 ms
8,612 KB
testcase_03 AC 21 ms
8,540 KB
testcase_04 AC 19 ms
8,624 KB
testcase_05 AC 22 ms
8,832 KB
testcase_06 AC 20 ms
8,608 KB
testcase_07 AC 20 ms
8,640 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 22 ms
8,680 KB
testcase_13 AC 20 ms
8,704 KB
testcase_14 AC 23 ms
8,832 KB
testcase_15 AC 25 ms
8,900 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 20 ms
8,588 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 19 ms
8,488 KB
testcase_22 AC 23 ms
8,880 KB
testcase_23 AC 24 ms
8,748 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 19 ms
8,660 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 19 ms
8,552 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
def countbinary(x):
    return bin(x).count("1")

n = int(input())
a = 1
list2 = []
flag = []
q = deque([])
for num2 in range(0,n+1):
    list2.append(10000000)
    flag.append(False)
list2[1] = 1
q.append(1)
judge = True
while judge:
    judge = False
    a = q.pop()
    num = int(countbinary(a))
    flag[a] = True
    if a - num > 0 and (flag[a-num] is False):
        list2[a-num]=min(list2[a]+1,list2[a-num])
        judge = True
        num3 = a - num
        q.append(num3)
    if a + num <= n and (flag[a+num] is False):
        list2[a+num]=min(list2[a] +1,list2[a+num])
        num4 = a + num
        judge = True
        q.append(num4)
if flag[n]:
    print(list2[n])
else:
    print(-1)
0