結果

問題 No.3 ビットすごろく
コンテスト
ユーザー qlt
提出日時 2025-10-25 01:07:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 668 bytes
コンパイル時間 457 ms
コンパイル使用メモリ 82,612 KB
実行使用メモリ 66,548 KB
最終ジャッジ日時 2025-10-25 01:07:20
合計ジャッジ時間 3,240 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

stack = []
answers = set()

stack.append([1, 1])
ok_flag = False

while stack:
    ceil = stack.pop()
    turn = ceil[0]
    now = ceil[1]

    dice = 0

    for j in range(14):
        if (now >> j) & 1 == 1:
            dice += 1
    
    f_now = now + dice
    p_now = now - dice

    if (f_now <= N) and (f_now not in answers):
        stack.append([turn + 1, f_now])
        answers.add(f_now)
        if f_now == N:
            ok_flag = True
            break
    if (p_now >= 1) and (p_now not in answers):
        stack.append([turn + 1, p_now])
        answers.add(p_now)

if ok_flag:
    a = stack.pop()
    print(a[0])
else:
    print(-1)
0