結果

問題 No.10 +か×か
コンテスト
ユーザー kutsutama
提出日時 2018-03-01 00:16:15
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
MLE  
実行時間 -
コード長 676 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 657 ms
コンパイル使用メモリ 20,828 KB
実行使用メモリ 1,107,748 KB
最終ジャッジ日時 2026-05-29 05:24:24
合計ジャッジ時間 8,029 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 MLE * 1 -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import collections

def dfs(memo, a, j, s, t, res):
    if j == len(a) - 1:
        if s == t:
            return True
        else:
            return False
    if s in memo[j]:
        return False

    memo[j].add(s)
    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