結果

問題 No.10 +か×か
ユーザー kutsutama
提出日時 2018-03-01 00:24:38
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 626 ms / 5,000 ms
コード長 721 bytes
コンパイル時間 375 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 86,804 KB
最終ジャッジ日時 2024-12-14 15:40:58
合計ジャッジ時間 2,296 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections

def dfs(memo, a, j, s, t, res):
    if s in memo[j]:
        return False
    memo[j].add(s)
    
    if s > t:
        return False

    if j == len(a) - 1:
        if s == t:
            return True
        else:
            return False

    if dfs(memo, a, j + 1, s + a[j + 1], t, res):
        res.append('+')
        return True
    if dfs(memo, a, j + 1, s * a[j + 1], t, res):
        res.append('*')
        return True
    else:
        return False

n = int(input())
t = int(input())
a = [int(x) for x in input().split()]

memo = []
for i in range(n):
    memo.append(set())

res = []

dfs(memo, a, 0, a[0], t, res)

res.reverse()
print(''.join(res))
0