結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
strn5
|
| 提出日時 | 2019-07-23 01:20:11 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 78 ms / 5,000 ms |
| コード長 | 652 bytes |
| コンパイル時間 | 80 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 11,520 KB |
| 最終ジャッジ日時 | 2024-07-01 09:26:11 |
| 合計ジャッジ時間 | 2,948 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
import queue
N = int(input())
sugoroku = [0] * N
sugoroku[0] = 1
def bit(x):
cnt = 0
while x != 0:
if x % 2 == 1:
cnt += 1
x = x // 2
return cnt
q = queue.Queue()
q.put(0)
while not q.empty():
pos = q.get()
move = bit(pos + 1)
if 0 <= pos - move <= N-1:
if sugoroku[pos - move] == 0:
sugoroku[pos - move] = sugoroku[pos] + 1
q.put(pos - move)
if 0 <= pos + move <= N-1:
if sugoroku[pos + move] == 0:
sugoroku[pos + move] = sugoroku[pos] + 1
q.put(pos + move)
if sugoroku[N-1] == 0:
print("-1")
else:
print(sugoroku[N-1])
strn5