結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
edash
|
| 提出日時 | 2018-08-19 20:48:32 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 5,000 ms |
| コード長 | 526 bytes |
| コンパイル時間 | 86 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 11,136 KB |
| 最終ジャッジ日時 | 2024-07-01 09:05:42 |
| 合計ジャッジ時間 | 2,206 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
n=int(input())
def f():
lst = [0]*(n+1)
lst[1] = 1
cnt = [1]
while(cnt):
num = cnt.pop(0)
if num == n:
return lst[num]
step = str(bin(num))[2:].count("1")
fowd_n = num + step
back_n = num - step
if fowd_n <= n and lst[fowd_n]==0:
cnt.append(fowd_n)
lst[fowd_n] =lst[num] + 1
if back_n > 0 and lst[back_n]==0:
cnt.append(back_n)
lst[back_n] =lst[num] + 1
return -1
print(f())
edash