結果

問題 No.10 +か×か
ユーザー 👑 rin204rin204
提出日時 2022-06-12 15:54:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 414 ms / 5,000 ms
コード長 488 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 81,804 KB
実行使用メモリ 124,408 KB
最終ジャッジ日時 2023-10-24 11:45:51
合計ジャッジ時間 2,685 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,464 KB
testcase_01 AC 36 ms
53,464 KB
testcase_02 AC 35 ms
53,464 KB
testcase_03 AC 141 ms
102,476 KB
testcase_04 AC 93 ms
76,224 KB
testcase_05 AC 36 ms
53,472 KB
testcase_06 AC 414 ms
124,408 KB
testcase_07 AC 143 ms
93,736 KB
testcase_08 AC 110 ms
78,568 KB
testcase_09 AC 82 ms
79,892 KB
testcase_10 AC 36 ms
53,464 KB
testcase_11 AC 36 ms
53,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
x = int(input())
A = list(map(int, input().split()))
ope = []

memo = set()
def dfs(t, tot):
    if t == n:
        if tot == x:
            print(*ope, sep="")
            exit()
        return
    if t + tot * n in memo:
        return
    if tot + A[t] <= x:
        ope.append("+")
        dfs(t + 1, tot + A[t])
        ope.pop()
    if tot * A[t] <= x:
        ope.append("*")
        dfs(t + 1, tot * A[t])
        ope.pop()
    memo.add(t + tot * n)

dfs(1, A[0])
0