結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
dashi_dragons
|
| 提出日時 | 2017-02-13 21:35:55 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 515 bytes |
| コンパイル時間 | 872 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 11,520 KB |
| 最終ジャッジ日時 | 2024-12-29 19:10:45 |
| 合計ジャッジ時間 | 3,036 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 WA * 22 |
ソースコード
def bitcnt(N):
cnt = 0
while N != 0:
if N % 2 == 1:
cnt += 1
N = N // 2
return cnt
N = int(input())
loc = 1
queue = [1]
list = {1:0}
cnt = 0
while True:
loc = queue[0]
cnt += 1
mov = bitcnt(loc)
if loc + mov <= N:
if loc + mov not in list:
list[loc + mov] = cnt
queue.append(loc + mov)
if loc - mov >= 1:
if loc - mov not in list:
list[loc - mov] = cnt
queue.append(loc - mov)
queue.remove(loc)
if queue == []:
break
if N not in list:
print(-1)
else:
print(list[N])
dashi_dragons