結果

問題 No.3 ビットすごろく
ユーザー GrayCoderGrayCoder
提出日時 2018-06-26 23:54:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 767 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 10,868 KB
実行使用メモリ 9,316 KB
最終ジャッジ日時 2023-09-13 14:15:41
合計ジャッジ時間 2,331 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,500 KB
testcase_01 AC 19 ms
8,620 KB
testcase_02 AC 18 ms
8,528 KB
testcase_03 AC 19 ms
8,796 KB
testcase_04 WA -
testcase_05 AC 22 ms
8,876 KB
testcase_06 AC 20 ms
8,680 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 22 ms
8,880 KB
testcase_13 AC 19 ms
8,652 KB
testcase_14 AC 23 ms
9,044 KB
testcase_15 AC 26 ms
9,284 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 17 ms
8,616 KB
testcase_22 AC 24 ms
9,060 KB
testcase_23 AC 26 ms
9,224 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 18 ms
8,632 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
from sys import stdin, stdout
input = lambda: stdin.readline().rstrip()
write = stdout.write

def bitCount(i):
    ret = 0
    while i:
        i &= i - 1
        ret += 1
    return ret

def main():
    N = int(input())

    que = deque([1])
    grid = [i for i in range(N + 1)]
    move = [None for _ in [0] * (N + 1)]
    move[1] = 1
    cnt = 1
    while que:
        flag = False
        n = que.popleft()
        i = bitCount(grid[n])
        for j in (n + i, n - i):
            if 0 < j <= N and move[j] is None:
                que.append(j)
                move[j] = cnt + 1
                flag = True
        if flag:
            cnt += 1

    if move[-1] is None:
        print(-1)
    else:
        print(move[-1])

main()
0