結果

問題 No.10 +か×か
コンテスト
ユーザー norioc
提出日時 2026-01-02 02:00:48
言語 PyPy3
(7.3.17)
結果
AC  
実行時間 1,527 ms / 5,000 ms
コード長 948 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 284 ms
コンパイル使用メモリ 82,448 KB
実行使用メモリ 269,824 KB
最終ジャッジ日時 2026-01-02 02:00:55
合計ジャッジ時間 5,482 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections.abc import Iterable


def accum_dp(xs: Iterable, f, op, e, init: dict, *, is_reset=True):
    dp = init.copy()
    for x in xs:
        pp = {} if is_reset else dp.copy()
        dp, pp = pp, dp
        for fm_key, fm_val in pp.items():
            for to_key, to_val in f(fm_key, fm_val, x):
                dp[to_key] = op(dp.get(to_key, e), to_val)

    return dp


INF = 1 << 62
N = int(input())
T = int(input())
A = list(map(int, input().split()))


def f(k, v, i):
    # key = 和
    # val = +/* の 2 進数
    if k + A[i] <= T:
        v_add = (v << 1) | 0
        yield k + A[i], v_add

    if k * A[i] <= T:
        v_mul = (v << 1) | 1
        yield k * A[i], v_mul


def op(a, b):
    return min(a, b)


init = {A[0]: 0}
dp = accum_dp(range(1, N), f, op, INF, init)

v = dp[T]
ans = []
for i in range(N-1):
    if v & (1 << i):
        ans.append('*')
    else:
        ans.append('+')

print(''.join(reversed(ans)))
0