結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-12-04 19:07:55 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 725 bytes |
| コンパイル時間 | 121 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-09-26 23:09:36 |
| 合計ジャッジ時間 | 2,682 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 19 |
ソースコード
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)
elif N ==1:
print(1)
else:
print(-1)