結果

問題 No.3 ビットすごろく
ユーザー pawn0818pawn0818
提出日時 2018-09-29 10:30:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,440 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-20 12:47:04
合計ジャッジ時間 3,020 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created: 金  9/28 23:04:27 2018

# Usage
#
"""
from collections import deque
def get():
    """
    """
    return int(input())

def get_each_cell_num(length):
    """
    >>> get_each_cell_num(5)
    [1, 1, 2, 1, 2]
    """
    def maker(num):
        return sum([int(i) for i in list(bin(num)[2:])])
    return [maker(i) for i in range(1, length+1)]

def bfs(res, goal, route):
    QUE = deque([])
    goal = goal - 1 # 配列と問題文のIndexは1差がある。
    res[0] = 0
    counter = 1
    QUE.append(0)

    while QUE: # Listが空だとFalse
        # print(res)
        counter += 1
        pos = QUE.popleft()
        # print(pos)
        if pos == goal: # ゴールに着いたら探索不要
            return res
        for i in [route[pos], -route[pos]]:
            next_pos = pos + i
            if next_pos >= len(res):
                continue
            if res[next_pos] != -1:
                continue
            if next_pos >= 0:
                QUE.append(next_pos)

                res[next_pos] = counter
    return res


def solve(length):
    """
    >>> solve(5)
    """
    res = [-1] * length
    route = get_each_cell_num(length)

    a = bfs(res,length, route)
    print(a[-1])


if __name__ == '__main__':
    solve(get())
0