結果

問題 No.1929 Exponential Sequence
ユーザー tamato
提出日時 2022-05-06 22:48:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 1,185 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 84,600 KB
最終ジャッジ日時 2024-09-14 03:53:50
合計ジャッジ時間 3,043 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353


def main():
    import sys
    from bisect import bisect_left
    input = sys.stdin.readline

    N, S = map(int, input().split())
    A_ori = list(map(int, input().split()))

    A_split = [A_ori[:4], A_ori[4:]]

    res_list = []
    for A in A_split:
        dp = {0: 1}
        for a in A:
            ax = 1
            dp_new = {}
            for x in range(31):
                ax *= a
                if ax > S:
                    break
                for y in dp:
                    y_new = y + ax
                    if y_new > S:
                        continue
                    if y_new not in dp_new:
                        dp_new[y_new] = 0
                    dp_new[y_new] += dp[y]
            dp = dp_new

        res = []
        for y in dp:
            res.append((y, dp[y]))
        res.sort(key=lambda z: z[0])
        res_list.append(res)

    res0, res1 = res_list
    val = []
    cnt_cs = [0]
    for y, c in res1:
        val.append(y)
        cnt_cs.append(cnt_cs[-1] + c)
    ans = 0
    for y, c in res0:
        j = bisect_left(val, S - y + 1)
        ans += cnt_cs[j] * c
    print(ans)


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