結果

問題 No.3 ビットすごろく
ユーザー dydy
提出日時 2020-10-08 23:05:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 762 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 8,792 KB
最終ジャッジ日時 2023-09-27 12:04:48
合計ジャッジ時間 2,228 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,536 KB
testcase_01 WA -
testcase_02 AC 18 ms
8,468 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 20 ms
8,708 KB
testcase_06 AC 19 ms
8,676 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 20 ms
8,756 KB
testcase_13 AC 18 ms
8,488 KB
testcase_14 AC 21 ms
8,628 KB
testcase_15 AC 21 ms
8,748 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 17 ms
8,472 KB
testcase_22 AC 21 ms
8,744 KB
testcase_23 AC 23 ms
8,608 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 17 ms
8,548 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n = int(input())

nums = [0]
cnt = 0
loop_num = 1
loop_flg = True
while loop_flg:
    for i in range(1, loop_num):
        nums.append(i)
        cnt += 1
        if cnt == n:
            loop_flg = False
            break
    loop_num += 1

steps = [None, 1]
for _ in range(2, n+1):
    steps.append(-1)

q = deque([])
start = 1
q.append(start)
while q:
    v = q.popleft()
    # print('num')
    # print(v)
    # print('step')
    # print(steps[v])
    if v == n:
        # print("goal")
        break
    num = nums[v]
    for next_v in [v + num, v - num]:
        if 1 <= next_v and next_v <= n:
            if steps[next_v] == -1:
                q.append(next_v)
                steps[next_v] = steps[v] + 1

print(steps[n])
0