結果

問題 No.10 +か×か
ユーザー kutsutamakutsutama
提出日時 2018-03-01 00:16:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 676 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 10,812 KB
実行使用メモリ 656,424 KB
最終ジャッジ日時 2023-08-24 18:08:37
合計ジャッジ時間 8,085 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 20 ms
8,628 KB
testcase_02 AC 20 ms
8,612 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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