結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2018-06-12 20:01:20 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 659 bytes |
コンパイル時間 | 83 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,392 KB |
最終ジャッジ日時 | 2024-06-30 13:55:02 |
合計ジャッジ時間 | 2,386 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | WA * 33 |
ソースコード
N = int(input()) que = [1] now = 1 visited = [False for i in range(N+1)] haba = [-1 for i in range(N+1)] visited[1] = True haba[1] = 1 haba_count = 0 while len(que) > 0: now = que.pop(0) print(now) haba_count += 1 step_width = bin(now).count("1") next_f = now + step_width next_b = now - step_width if next_f <= N and visited[next_f] is False: que.append(next_f) visited[next_f] = True haba[next_f] = haba_count if next_b >= 1 and visited[next_b] is False: que.append(next_b) visited[next_b] = True haba[next_b] = haba_count if now == N: print(haba[N]) else: print(-1)