結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,112 KB
testcase_01 AC 30 ms
10,112 KB
testcase_02 AC 29 ms
10,112 KB
testcase_03 AC 37 ms
10,112 KB
testcase_04 WA -
testcase_05 AC 47 ms
10,112 KB
testcase_06 AC 39 ms
10,112 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 46 ms
10,112 KB
testcase_13 AC 35 ms
10,112 KB
testcase_14 AC 58 ms
10,112 KB
testcase_15 AC 62 ms
10,112 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 29 ms
10,112 KB
testcase_22 AC 56 ms
10,112 KB
testcase_23 AC 64 ms
10,112 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=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)
    for i in [p+bitcount(p),p-bitcount(p)]:
        if 1<=i and i<=N and flag[i]==False:
            stack.append(i)
            flag[i]=True
            cntF=True
            if i == N:
                break
    if cntF:
        cnt+=1
        cntF=False
if i==N:
    print(cnt)
else:
    print(-1)
0