結果

問題 No.1463 Hungry Kanten
ユーザー 小野寺健小野寺健
提出日時 2021-04-29 15:04:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 852 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 10,980 KB
実行使用メモリ 20,464 KB
最終ジャッジ日時 2023-09-22 23:42:51
合計ジャッジ時間 5,662 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
12,424 KB
testcase_01 AC 16 ms
7,992 KB
testcase_02 AC 99 ms
8,688 KB
testcase_03 AC 1,775 ms
8,040 KB
testcase_04 AC 17 ms
8,036 KB
testcase_05 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

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