結果

問題 No.10 +か×か
コンテスト
ユーザー zimpha
提出日時 2017-12-07 02:26:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 147 ms / 5,000 ms
コード長 533 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 82,124 KB
実行使用メモリ 103,780 KB
最終ジャッジ日時 2024-12-14 15:40:43
合計ジャッジ時間 1,639 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
m = int(input())
a = list(map(int, input().split()))
inf = 1 << 60

f = [inf] * (m + 1)
f[0] = 0
for i, x in enumerate(a):
    g = [inf] * (m + 1)
    for j in range(m + 1):
        if f[j] == inf: continue
        if j + x <= m:
            g[j + x] = min(g[j + x], f[j])
        if j * x <= m:
            g[j * x] = min(g[j * x], f[j] | (1 << (n - i)))
    f = g
mask = f[m]
res = []
for i in range(n - 1, 0, -1):
    if mask >> i & 1:
        res.append('*')
    else:
        res.append('+')
print(''.join(res))
0