結果

問題 No.10 +か×か
ユーザー zimphazimpha
提出日時 2017-12-07 02:26:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 174 ms / 5,000 ms
コード長 533 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 87,040 KB
実行使用メモリ 116,264 KB
最終ジャッジ日時 2023-08-21 06:24:08
合計ジャッジ時間 2,356 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,148 KB
testcase_01 AC 71 ms
71,128 KB
testcase_02 AC 71 ms
70,996 KB
testcase_03 AC 174 ms
116,244 KB
testcase_04 AC 112 ms
102,424 KB
testcase_05 AC 72 ms
71,344 KB
testcase_06 AC 172 ms
116,264 KB
testcase_07 AC 125 ms
102,576 KB
testcase_08 AC 97 ms
83,736 KB
testcase_09 AC 102 ms
90,520 KB
testcase_10 AC 78 ms
75,744 KB
testcase_11 AC 78 ms
75,568 KB
権限があれば一括ダウンロードができます

ソースコード

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