結果

問題 No.10 +か×か
ユーザー tktk_snsntktk_snsn
提出日時 2021-10-26 23:48:52
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 639 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 82,164 KB
実行使用メモリ 141,352 KB
最終ジャッジ日時 2024-04-16 00:12:01
合計ジャッジ時間 1,965 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
54,272 KB
testcase_01 AC 44 ms
54,272 KB
testcase_02 AC 49 ms
54,016 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 45 ms
54,400 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 96 ms
88,832 KB
testcase_10 AC 49 ms
60,928 KB
testcase_11 AC 47 ms
60,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import heapq
inf = 10 ** 18
N = int(input())
T = int(input())
A = list(map(int, input().split()))

dp = [[0] * (T + 1) for _ in range(N)]
dp[0][A[0]] = 1
for i in range(1, N):
    for s in range(1, T+1):
        if dp[i-1][s]:
            t = s * A[i]
            if t <= T:
                dp[i][t] = True
            t = s + A[i]
            if t <= T:
                dp[i][t] = True

ans = []
now = T
for i in reversed(range(N - 1)):
    if dp[i][now - A[i+1]]:
        now -= A[i+1]
        ans.append("+")
    else:
        now //= A[i+1]
        ans.append("*")

ans.reverse()
print("".join(ans))
0