結果

問題 No.3 ビットすごろく
ユーザー トミートミー
提出日時 2023-12-04 19:00:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 700 bytes
コンパイル時間 584 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 10,368 KB
最終ジャッジ日時 2023-12-04 19:00:12
合計ジャッジ時間 3,822 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,240 KB
testcase_01 AC 28 ms
10,240 KB
testcase_02 AC 30 ms
10,240 KB
testcase_03 AC 36 ms
10,240 KB
testcase_04 WA -
testcase_05 AC 73 ms
10,240 KB
testcase_06 AC 38 ms
10,240 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 47 ms
10,240 KB
testcase_13 AC 36 ms
10,240 KB
testcase_14 AC 57 ms
10,368 KB
testcase_15 AC 65 ms
10,368 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 30 ms
10,240 KB
testcase_22 AC 57 ms
10,368 KB
testcase_23 AC 74 ms
10,368 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
def bitcount(n):
    cnt=0
    while n!=0:
        cnt+=n%2
        n=math.floor(n/2)
    return cnt
N=int(input())
cnt=2
cntF=False
flag=[False for i in range(N+1)]
flag[1]=True
stack=[1]
p=0
while len(stack)!=0 and p!=N:
    p = stack.pop(0)
    up=p+bitcount(p)
    down=p-bitcount(p)
    if up<=N and flag[up]==False:
        stack.append(up)
        flag[up]=True
        cntF=True
        if up==N:
            break
    if down>=1 and down<=N and flag[down]==False:
        stack.append(down)
        flag[down]=True
        cntF=True
        if down == N:
            break
    if cntF:
        cnt+=1
        cntF=False
if up == N or down == N:
    print(cnt)
else:
    print(-1)
0