結果

問題 No.1463 Hungry Kanten
ユーザー 小野寺健小野寺健
提出日時 2021-04-29 15:58:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,693 ms / 2,000 ms
コード長 712 bytes
コンパイル時間 126 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 31,736 KB
最終ジャッジ日時 2023-09-23 00:37:45
合計ジャッジ時間 7,327 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,948 KB
testcase_01 AC 15 ms
7,964 KB
testcase_02 AC 74 ms
8,888 KB
testcase_03 AC 1,652 ms
7,940 KB
testcase_04 AC 17 ms
7,852 KB
testcase_05 AC 1,693 ms
31,736 KB
testcase_06 AC 16 ms
7,796 KB
testcase_07 AC 16 ms
7,936 KB
testcase_08 AC 16 ms
7,824 KB
testcase_09 AC 16 ms
7,972 KB
testcase_10 AC 16 ms
7,824 KB
testcase_11 AC 18 ms
8,224 KB
testcase_12 AC 19 ms
8,324 KB
testcase_13 AC 17 ms
7,852 KB
testcase_14 AC 32 ms
8,532 KB
testcase_15 AC 23 ms
8,316 KB
testcase_16 AC 75 ms
9,676 KB
testcase_17 AC 193 ms
10,944 KB
testcase_18 AC 98 ms
8,792 KB
testcase_19 AC 796 ms
19,752 KB
testcase_20 AC 1,093 ms
20,728 KB
testcase_21 AC 17 ms
7,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 = dict()

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]
        if s not in ans:
            ans[s] = True
        if p not in ans:
            ans[p] = True
print(len(ans))
0