結果

問題 No.3 ビットすごろく
ユーザー ktnyktny
提出日時 2016-07-19 00:22:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 742 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-23 16:37:53
合計ジャッジ時間 2,294 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

N = int(input())
array = []
for i in range(1, N):
    array.append(str(bin(i))[2:].count("1"))

count = 0
queue = [0]

while(True):
    count += 1
    n = array[queue[0]] # 現在の位置のビット数をnに代入
    array[queue[0]] = 0 # 訪問履歴を0で表現する。すでに訪問した位置のビット数は0
    a = queue[0] + n # 現在の位置+現在の位置のビット数をaに代入
    b = queue[0] - n # 現在の位置-現在の位置のビット数をbに代入
    queue.pop(0)
    if(a == N - 1):
        break
    if(0 < a < N - 1 and array[a] != 0):
        queue.append(a)
    if(0 < b < N - 1 and array[b] != 0):
        queue.append(b)
    if(len(queue) == 0):
        count = -1
        break

print(count)
0