結果

問題 No.10 +か×か
コンテスト
ユーザー ゆるく
提出日時 2014-11-10 22:47:08
言語 Python3
(3.14.2 + numpy 2.4.0 + scipy 1.16.3)
結果
AC  
実行時間 598 ms / 5,000 ms
コード長 637 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 121 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 49,884 KB
最終ジャッジ日時 2025-12-06 14:29:21
合計ジャッジ時間 2,456 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy

n = int(input())
total = int(input())
a = [int(i) for i in input().split()]
ans = [''] * 50
memo = defaultdict(lambda:defaultdict(int))
def solve(i, t):
  if t == total and i == n - 1:
    print(''.join(ans))
    sys.exit(0)
  if i >= n - 1 or t > total or memo[i][t]:
    return
  ans[i] = '+'
  solve(i + 1, t + a[i + 1])
  ans[i] = '*'
  solve(i + 1, t * a[i + 1])
  memo[i][t] = True
  return

t = a[0]
solve(0, t)
0