結果

問題 No.1825 Except One
ユーザー brthyyjp
提出日時 2022-01-28 22:14:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,814 ms / 3,000 ms
コード長 932 bytes
コンパイル時間 446 ms
コンパイル使用メモリ 82,324 KB
実行使用メモリ 277,416 KB
最終ジャッジ日時 2025-01-01 23:12:42
合計ジャッジ時間 10,333 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():

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

    #A.sort(reverse=True)

    from collections import defaultdict
    dp = defaultdict(lambda: 0)
    def getindex(k, s, M):
        return (k<<36)+(s<<18)+M
    dp[getindex(0, 0, 0)] = 1
    for a in A:
        nx = defaultdict(lambda: 0)
        for p, v in dp.items():
            k = p>>36
            r = p-(k<<36)
            s = r>>18
            M = r-(s<<18)
            #if s < M*(k-1):
                #continue
            nx[getindex(k, s, M)] += v
            nx[getindex(k+1, s+a, max(M, a))] += v
        dp = nx
    #print(dp)
    ans = 0
    for p, v in dp.items():
        k = p>>36
        r = p-(k<<36)
        s = r>>18
        M = r-(s<<18)
        if k <= 1:
            continue
        if s%(k-1) == 0:
            x = s//(k-1)
            if x >= M:
                ans += v
    print(ans)

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