結果

問題 No.1825 Except One
ユーザー lam6er
提出日時 2025-03-31 17:26:15
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 765 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 82,848 KB
実行使用メモリ 55,384 KB
最終ジャッジ日時 2025-03-31 17:27:42
合計ジャッジ時間 5,614 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 TLE * 1
other -- * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))

dp = defaultdict(int)
dp[(0, 0, 0)] = 1

for num in a:
    next_dp = defaultdict(int)
    
    # Copy existing entries (exclude current number)
    for key, count in dp.items():
        next_dp[key] += count
    
    # Add entries where current number is included
    for (m, s, max_v), count in dp.items():
        new_m = m + 1
        new_s = s + num
        new_max = max(max_v, num)
        next_dp[(new_m, new_s, new_max)] += count
    
    dp = next_dp

result = 0
for (m, s, max_v), count in dp.items():
    if m >= 2:
        if (s % (m - 1)) == 0:
            required = s // (m - 1)
            if required >= max_v:
                result += count

print(result)
0