結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
dashi_dragons
|
| 提出日時 | 2017-02-13 21:48:56 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 51 ms / 5,000 ms |
| コード長 | 548 bytes |
| コンパイル時間 | 89 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 11,520 KB |
| 最終ジャッジ日時 | 2024-07-01 08:18:27 |
| 合計ジャッジ時間 | 2,479 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
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,1)]
list = {1:1}
while True:
loc = queue[0][0]
cnt = queue[0][1] + 1
mov = bitcnt(loc)
if loc + mov <= N:
if loc + mov not in list:
list[loc + mov] = cnt
queue.append((loc + mov,cnt))
if loc - mov >= 1:
if loc - mov not in list:
list[loc - mov] = cnt
queue.append((loc - mov,cnt))
queue.pop(0)
if queue == []:
break
#print(list)
if N not in list:
print(-1)
else:
print(list[N])
dashi_dragons