結果

問題 No.10 +か×か
ユーザー szkhtsszkhts
提出日時 2020-10-23 11:58:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 570 bytes
コンパイル時間 758 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 48,440 KB
最終ジャッジ日時 2023-09-28 15:19:25
合計ジャッジ時間 4,114 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,132 KB
testcase_01 AC 17 ms
8,060 KB
testcase_02 AC 17 ms
8,068 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 16 ms
8,204 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 17 ms
8,296 KB
testcase_11 AC 16 ms
8,120 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]:
        print("dp2:", 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