結果

問題 No.10 +か×か
ユーザー taisuketaisuke
提出日時 2023-02-21 23:07:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 560 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 48,312 KB
最終ジャッジ日時 2023-09-29 12:40:54
合計ジャッジ時間 8,289 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,848 KB
testcase_01 AC 14 ms
7,804 KB
testcase_02 AC 15 ms
7,752 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 15 ms
7,756 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 332 ms
22,672 KB
testcase_10 AC 19 ms
8,248 KB
testcase_11 AC 16 ms
8,236 KB
権限があれば一括ダウンロードができます

ソースコード

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