結果

問題 No.10 +か×か
ユーザー szkhtsszkhts
提出日時 2020-10-23 12:00:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 627 ms / 5,000 ms
コード長 536 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 10,712 KB
実行使用メモリ 48,144 KB
最終ジャッジ日時 2023-08-21 06:32:27
合計ジャッジ時間 2,849 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,244 KB
testcase_01 AC 15 ms
8,144 KB
testcase_02 AC 16 ms
8,172 KB
testcase_03 AC 478 ms
48,044 KB
testcase_04 AC 182 ms
34,404 KB
testcase_05 AC 15 ms
8,144 KB
testcase_06 AC 627 ms
48,144 KB
testcase_07 AC 353 ms
34,356 KB
testcase_08 AC 80 ms
15,936 KB
testcase_09 AC 132 ms
22,700 KB
testcase_10 AC 18 ms
8,400 KB
testcase_11 AC 17 ms
8,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

N = int(input())
Total = int(input())
A = list(map(int, input().split()))
dp = [[0 for _ in range(Total + 1)] for _ in range(N + 1)]

def dfs(ops, cur, v):
    if v > Total:
        return
    if cur == N:
        if v == Total:
            print(ops) 
            sys.exit()
        return
    if dp[cur][v]:
        return
    
    dp[cur][v] = 1
    ops += '+'
    dfs(ops, cur + 1, v + A[cur])
    ops = ops[0 : -1]
    
    ops += '*'
    dfs(ops, cur + 1, v * A[cur])
    ops = ops[0 : -1]

ops = ''
dfs(ops, 1, A[0])
0