結果

問題 No.3 ビットすごろく
ユーザー piconic_Xpiconic_X
提出日時 2016-08-12 19:57:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 878 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-25 02:38:01
合計ジャッジ時間 4,068 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,880 KB
testcase_01 AC 27 ms
10,752 KB
testcase_02 AC 28 ms
10,752 KB
testcase_03 AC 87 ms
10,880 KB
testcase_04 AC 33 ms
10,880 KB
testcase_05 AC 314 ms
11,136 KB
testcase_06 AC 102 ms
10,880 KB
testcase_07 AC 51 ms
10,880 KB
testcase_08 WA -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 299 ms
11,136 KB
testcase_13 AC 69 ms
10,880 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 61 ms
10,880 KB
testcase_19 RE -
testcase_20 WA -
testcase_21 AC 26 ms
10,752 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 28 ms
10,752 KB
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
testcase_30 WA -
testcase_31 AC 26 ms
10,752 KB
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def get_bitnum(n):
    i = 0
    while n > 0:
        if n % 2 == 1:
            i += 1
        n = n // 2
    return i


def create_route(N):
    route = [get_bitnum(i+1) for i in range (N)]
    return route

N = int(input())
route = create_route(N)
history = []
res = []

def search(pos, time):
    if pos == N-1:
        res.append(time)
    else:
        history.append(pos)
        bitnum = route[pos]
        posR = pos + bitnum
        posL = pos - bitnum
        RB = not (posR > N-1 or posR in history)
        LB = not (posL < 1 or posL in history)
        if RB and LB:
            return search(posR, time+1), search(posL, time+1)
        elif RB and not LB:
            return search(posR, time+1)
        elif LB and not RB:
            return search(posL, time+1)
        else:
            pass

search(0, 1)

if res == []:
    print(-1)
else:
    print(min(res))
0