結果

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

テストケース

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

ソースコード

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=1
cntF=False
flag=[False for i in range(N+1)]
flag[1]=True
stack=[1]
p=0
i=0
while len(stack)!=0 and i!=N:
    p = stack.pop(0)
    flag[p]=True
    for i in [p+bitcount(p),p-bitcount(p)]:
        if 1<=i and i<=N and flag[i]==False:
            stack.append(i)
            cntF=True
            if i == N:
                break
    if cntF:
        cnt+=1
        cntF=False
if i==N:
    print(cnt)
elif N == 1:
    print(1)
else:
    print(-1)
0