結果

問題 No.3 ビットすごろく
ユーザー mojamojammojamojam
提出日時 2020-07-31 17:17:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 953 bytes
コンパイル時間 557 ms
コンパイル使用メモリ 10,876 KB
実行使用メモリ 15,140 KB
最終ジャッジ日時 2023-09-20 17:42:02
合計ジャッジ時間 7,318 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,948 KB
testcase_01 AC 15 ms
7,800 KB
testcase_02 AC 16 ms
7,996 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

var = -1
def popcount(x):
    '''xの立っているビット数をカウントする関数
    (xは64bit整数)'''

    # 2bitごとの組に分け、立っているビット数を2bitで表現する
    x = x - ((x >> 1) & 0x5555555555555555)

    # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと
    x = x + (x >> 8) # 16bitごと
    x = x + (x >> 16) # 32bitごと
    x = x + (x >> 32) # 64bitごと = 全部の合計
    return x & 0x0000007f

def calc(i, n, count):
    global var
    tile_list.append(i)
    num = i + popcount(i)
    if num == n:
        var = count + 1
    if num < n:
        calc(num, n, count+1)
    num = i - popcount(i)
    if not num in tile_list and num > 0:
        calc(num, n, count+1)

n = int(input())
tile_list = list()
i = 1
count = 1
calc(i, n, count)
print(var)
0