結果

問題 No.3 ビットすごろく
ユーザー zinnnia123zinnnia123
提出日時 2019-08-29 00:58:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 35 ms / 5,000 ms
コード長 623 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 10,852 KB
実行使用メモリ 9,012 KB
最終ジャッジ日時 2023-09-14 01:26:16
合計ジャッジ時間 2,381 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,684 KB
testcase_01 AC 19 ms
8,532 KB
testcase_02 AC 19 ms
8,580 KB
testcase_03 AC 24 ms
8,564 KB
testcase_04 AC 20 ms
8,580 KB
testcase_05 AC 27 ms
8,804 KB
testcase_06 AC 23 ms
8,604 KB
testcase_07 AC 22 ms
8,564 KB
testcase_08 AC 27 ms
8,668 KB
testcase_09 AC 29 ms
8,820 KB
testcase_10 AC 32 ms
8,844 KB
testcase_11 AC 29 ms
8,876 KB
testcase_12 AC 27 ms
8,728 KB
testcase_13 AC 22 ms
8,700 KB
testcase_14 AC 31 ms
8,816 KB
testcase_15 AC 35 ms
8,836 KB
testcase_16 AC 33 ms
8,948 KB
testcase_17 AC 34 ms
8,812 KB
testcase_18 AC 21 ms
8,688 KB
testcase_19 AC 34 ms
8,976 KB
testcase_20 AC 19 ms
8,556 KB
testcase_21 AC 19 ms
8,692 KB
testcase_22 AC 32 ms
8,844 KB
testcase_23 AC 35 ms
8,820 KB
testcase_24 AC 35 ms
8,916 KB
testcase_25 AC 35 ms
9,012 KB
testcase_26 AC 19 ms
8,688 KB
testcase_27 AC 22 ms
8,608 KB
testcase_28 AC 33 ms
8,952 KB
testcase_29 AC 29 ms
8,744 KB
testcase_30 AC 19 ms
8,684 KB
testcase_31 AC 19 ms
8,664 KB
testcase_32 AC 28 ms
8,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = int(input())

Dice = [0]*(N+1)
Seen = [0]*(N+1)
Todo = deque([])

for i in range(N+1):
    Dice[i] = int(bin(i).count('1'))

Todo.append(1)
Seen[1] = 1

while len(Todo) >= 1:
    A = Todo.popleft()
    if A + Dice[A] <= N:
        if Seen[A+Dice[A]] == 0 or Seen[A+Dice[A]] > Seen[A] +1:
            Todo.append(A+Dice[A])
            Seen[A+Dice[A]] = Seen[A] + 1
    if A - Dice[A] <= N:
        if Seen[A-Dice[A]] == 0 or Seen[A-Dice[A]] > Seen[A] +1:
            Todo.append(A-Dice[A])
            Seen[A-Dice[A]] = Seen[A] + 1

if Seen[N] == 0:
    print(-1)
else:
    print(Seen[N])
0