結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2023-12-04 21:38:23 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 560 bytes |
コンパイル時間 | 327 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-09-26 23:15:00 |
合計ジャッジ時間 | 3,046 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 WA * 20 |
ソースコード
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)