結果

問題 No.10 +か×か
ユーザー ゆるくゆるく
提出日時 2014-11-10 22:47:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 490 ms / 5,000 ms
コード長 637 bytes
コンパイル時間 423 ms
コンパイル使用メモリ 10,764 KB
実行使用メモリ 48,812 KB
最終ジャッジ日時 2023-08-21 06:08:16
合計ジャッジ時間 2,919 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
9,900 KB
testcase_01 AC 29 ms
9,852 KB
testcase_02 AC 29 ms
9,868 KB
testcase_03 AC 286 ms
31,984 KB
testcase_04 AC 35 ms
10,444 KB
testcase_05 AC 30 ms
10,032 KB
testcase_06 AC 490 ms
48,812 KB
testcase_07 AC 239 ms
28,688 KB
testcase_08 AC 47 ms
11,564 KB
testcase_09 AC 59 ms
12,796 KB
testcase_10 AC 30 ms
9,860 KB
testcase_11 AC 30 ms
9,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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