結果

問題 No.10 +か×か
ユーザー taisuke
提出日時 2023-02-21 23:07:06
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 560 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 50,944 KB
最終ジャッジ日時 2024-07-22 07:01:05
合計ジャッジ時間 8,036 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
t = int(input())
a = list(map(int, input().split()))

dp = [[0 for i in range(t+1)] for j in range(n+1)]
dp[1][a[0]] = 1

for i in range(1, n):
    for j in range(t+1):
        if dp[i][j] != 0:
            x = j + a[i]
            if x <= t:
                dp[i+1][x] = dp[i][j]
            x = j * a[i]
            if x <= t:
                dp[i+1][x] = dp[i][j]
ans = str()
for i in reversed(range(1, n)):
    if dp[i][t - a[i]] == 1:
        ans += '+'
        t -= a[i]
    else:
        ans += '*'
        t //= a[i]

print(ans[::-1])
0