結果

問題 No.3 ビットすごろく
コンテスト
ユーザー kutsutama
提出日時 2018-03-01 23:11:13
言語 Python3
(3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 600 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 55 ms
コンパイル使用メモリ 14,976 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2026-10-08 01:23:20
合計ジャッジ時間 2,723 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def CountOne(num):
    res = 0
    while num >= 1:
        if num % 2 == 1:
            res += 1
        num //= 2
    return res

n = int(input())
u = set()

res = 1
p = 1
while p != n:
    u.add(p)
    go = CountOne(p)
    if p + go <= n:
        if (p + go) not in u:
            p += go
        else:
            if (p - go) not in u:
                p -= go
            else:
                res = -1
                break
    else:
        if (p - go) not in u:
            p -= go
        else:
            res = -1
            break
    res += 1

print(res)
0