結果

問題 No.3 ビットすごろく
ユーザー cleanttedcleantted
提出日時 2016-09-10 03:34:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 37 ms / 5,000 ms
コード長 566 bytes
コンパイル時間 121 ms
コンパイル使用メモリ 10,740 KB
実行使用メモリ 8,608 KB
最終ジャッジ日時 2023-09-14 00:06:53
合計ジャッジ時間 2,304 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,860 KB
testcase_01 AC 18 ms
7,860 KB
testcase_02 AC 18 ms
7,868 KB
testcase_03 AC 23 ms
7,784 KB
testcase_04 AC 18 ms
7,792 KB
testcase_05 AC 27 ms
8,300 KB
testcase_06 AC 22 ms
8,324 KB
testcase_07 AC 19 ms
7,956 KB
testcase_08 AC 24 ms
8,384 KB
testcase_09 AC 31 ms
8,548 KB
testcase_10 AC 33 ms
8,428 KB
testcase_11 AC 30 ms
8,332 KB
testcase_12 AC 28 ms
8,376 KB
testcase_13 AC 21 ms
7,800 KB
testcase_14 AC 33 ms
8,420 KB
testcase_15 AC 37 ms
8,480 KB
testcase_16 AC 35 ms
8,552 KB
testcase_17 AC 36 ms
8,524 KB
testcase_18 AC 20 ms
7,788 KB
testcase_19 AC 37 ms
8,440 KB
testcase_20 AC 17 ms
7,792 KB
testcase_21 AC 16 ms
7,804 KB
testcase_22 AC 33 ms
8,476 KB
testcase_23 AC 37 ms
8,608 KB
testcase_24 AC 37 ms
8,476 KB
testcase_25 AC 37 ms
8,476 KB
testcase_26 AC 16 ms
7,736 KB
testcase_27 AC 22 ms
7,904 KB
testcase_28 AC 34 ms
8,460 KB
testcase_29 AC 29 ms
8,436 KB
testcase_30 AC 16 ms
7,800 KB
testcase_31 AC 16 ms
7,916 KB
testcase_32 AC 30 ms
8,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
iadd = []
inow = [-1] * N
stack = []
for k in range(N):
    a = list(format(k+1,'b'))
    iadd.append(a.count("1"))

i = 0
inow[0] = 1
while i < N-1:
    for j in range(2):
        inx = i + (-1) ** j * iadd[i]
        if inx == N - 1:
            inow[inx] = inow[i] + 1
            stack = [inx]
            break
        elif -1 < inx < N - 1 :
            if inow[inx] == -1:
                stack.append(inx)
                inow[inx] = inow[i] + 1
    if stack ==[]: break

    else:
        i = stack[0]
        stack.pop(0)

print(inow[N-1])
0