結果

問題 No.10 +か×か
ユーザー H3PO4H3PO4
提出日時 2021-02-05 08:15:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 666 ms / 5,000 ms
コード長 488 bytes
コンパイル時間 510 ms
コンパイル使用メモリ 10,940 KB
実行使用メモリ 73,004 KB
最終ジャッジ日時 2023-08-21 06:32:53
合計ジャッジ時間 2,443 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,480 KB
testcase_01 AC 18 ms
8,492 KB
testcase_02 AC 19 ms
8,608 KB
testcase_03 AC 372 ms
44,596 KB
testcase_04 AC 27 ms
9,568 KB
testcase_05 AC 19 ms
8,488 KB
testcase_06 AC 666 ms
73,004 KB
testcase_07 AC 304 ms
40,068 KB
testcase_08 AC 42 ms
12,920 KB
testcase_09 AC 56 ms
14,000 KB
testcase_10 AC 19 ms
8,560 KB
testcase_11 AC 18 ms
8,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = int(input())
T = int(input())
A = tuple(map(int, input().split()))
stk = deque()
visited = set()


def rec(i, x):
    if (i, x) in visited:
        return
    if i == N and x == T:
        res = ''.join(map(str, stk))
        print(res)
        exit()
    elif i == N or x > T:
        return

    stk.append('+')
    rec(i + 1, x + A[i])
    stk.pop()

    stk.append('*')
    rec(i + 1, x * A[i])
    stk.pop()

    visited.add((i, x))


rec(1, A[0])
0