結果

問題 No.1463 Hungry Kanten
ユーザー 小野寺健
提出日時 2021-04-29 15:04:37
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 852 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 27,040 KB
最終ジャッジ日時 2024-07-16 00:18:44
合計ジャッジ時間 5,730 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 3 TLE * 1 -- * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

def popcount(x):
    x = x - ((x >> 1) & 0x55555555)

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

    x = (x + (x >> 4)) & 0x0f0f0f0f # 8bitごと
    x = x + (x >> 8) # 16bitごと
    x = x + (x >> 16) # 32bitごと
    return x & 0x0000007f

N, K = map(int, input().split())
A = list(map(int, input().split()))

ans = []

for a in range(1, 1 << N):
    if popcount(a) >= K:
        s , p = 0, 1
        for i in range(N):
            if ((a >> i) & 1):
                s += A[i]
                p *= A[i]
        j = bisect.bisect_left(ans, s)
        if j == len(ans) or ans[j] != s:
            ans.insert(j, s)
        j = bisect.bisect_left(ans, p)
        if j == len(ans) or ans[j] != p:
            ans.insert(j, p)
            
print(len(ans))
0