結果

問題 No.10 +か×か
ユーザー szkhtsszkhts
提出日時 2022-04-28 07:53:21
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 2,685 ms / 5,000 ms
コード長 637 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 10,820 KB
実行使用メモリ 48,184 KB
最終ジャッジ日時 2023-09-10 16:47:24
合計ジャッジ時間 12,405 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,916 KB
testcase_01 AC 15 ms
7,816 KB
testcase_02 AC 15 ms
7,816 KB
testcase_03 AC 2,685 ms
48,132 KB
testcase_04 AC 2,007 ms
34,496 KB
testcase_05 AC 16 ms
7,780 KB
testcase_06 AC 2,628 ms
48,184 KB
testcase_07 AC 2,128 ms
34,348 KB
testcase_08 AC 506 ms
16,160 KB
testcase_09 AC 1,071 ms
22,728 KB
testcase_10 AC 27 ms
8,356 KB
testcase_11 AC 18 ms
8,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
total = int(input())
A = list(map(int, input().split()))

dp = [[0 for _ in range(total + 1)] for _ in range(N + 1)]
dp[N][total] = 1

for i in range(N - 1, -1, -1):
    for j in range(total + 1):
        if j + A[i] <= total and dp[i + 1][j + A[i]] == 1:
            dp[i][j] = 1

        if j * A[i] <= total and dp[i + 1][j * A[i]] == 1:
            dp[i][j] = 1

j = A[0]
ans = ''
for i in range(1, N):
    if j + A[i] <= total and dp[i + 1][j + A[i]] == 1:
        ans += '+'
        j += A[i]
        continue
    if j * A[i] <= total and dp[i + 1][j * A[i]] == 1:
        ans += '*'
        j *= A[i]

print(ans)
0