結果

問題 No.1238 選抜クラス
ユーザー lam6er
提出日時 2025-03-20 20:21:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,218 ms / 2,000 ms
コード長 1,208 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 82,712 KB
実行使用メモリ 274,040 KB
最終ジャッジ日時 2025-03-20 20:23:04
合計ジャッジ時間 14,408 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

MOD = 10**9 + 7

def main():
    import sys
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx])
    idx += 1
    K = int(input[idx])
    idx += 1
    A = list(map(int, input[idx:idx + N]))
    idx += N
    
    x_list = [a - K for a in A]
    
    dp = defaultdict(lambda: defaultdict(int))
    dp[0][0] = 1
    
    for x in x_list:
        temp_dp = defaultdict(lambda: defaultdict(int))
        for c in list(dp.keys()):
            for s in list(dp[c].keys()):
                cnt = dp[c][s]
                # Not choose current x: retain the state
                temp_dp[c][s] = (temp_dp[c][s] + cnt) % MOD
                # Choose current x: add to new_c and new_s
                new_c = c + 1
                new_s = s + x
                temp_dp[new_c][new_s] = (temp_dp[new_c][new_s] + cnt) % MOD
        dp = temp_dp
    
    ans = 0
    for c in list(dp.keys()):
        if c < 1:
            continue
        current = dp[c]
        total = 0
        for s in current:
            if s >= 0:
                total = (total + current[s]) % MOD
        ans = (ans + total) % MOD
    print(ans % MOD)

if __name__ == "__main__":
    main()
0