結果

問題 No.10 +か×か
コンテスト
ユーザー H3PO4
提出日時 2021-02-05 08:15:15
言語 Python3
(3.14.2 + numpy 2.4.0 + scipy 1.16.3)
結果
AC  
実行時間 791 ms / 5,000 ms
コード長 488 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 97 ms
コンパイル使用メモリ 12,288 KB
実行使用メモリ 75,032 KB
最終ジャッジ日時 2025-12-06 14:58:03
合計ジャッジ時間 2,782 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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