結果

問題 No.10 +か×か
ユーザー gahougahou
提出日時 2016-11-11 17:59:47
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 925 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 6,628 KB
実行使用メモリ 247,080 KB
最終ジャッジ日時 2023-08-16 18:37:44
合計ジャッジ時間 8,424 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
247,080 KB
testcase_01 AC 11 ms
5,872 KB
testcase_02 AC 11 ms
6,048 KB
testcase_03 AC 1,674 ms
45,124 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def routing(dp, A, n, total, route):
  if n==0: return route
  ans=[]
  if dp[n][total]==1:
    for r in route:
      ans.append("+"+r)
    return routing(dp,A,n-1,total-A[n],ans)
  elif dp[n][total]==2:
    for r in route:
      ans.append("*"+r)
    return routing(dp,A,n-1,total/A[n],ans)
  elif dp[n][total]==3:
    for r in route:
      e1=[]
      e2=[]
      e1.append("+"+r)
      e2.append("*"+r)
    a1=routing(dp,A,n-1,total-A[n],e1)
    a2=routing(dp,A,n-1,total/A[n],e2)
    return a1+a2

N=int(raw_input())
T=int(raw_input())
A=map(int,raw_input().split())
dp=[[0]*(T+1) for _ in xrange(N)]
dp[0][A[0]]=1
for i in xrange(1,N):
  # sum
  for j in xrange(T):
    if dp[i-1][j]>0 and j+A[i]<=T:
      dp[i][j+A[i]]+=1
  # multiple
  for j in xrange(T/A[i]+1):
    if dp[i-1][j]>0 and j*A[i]<=T:
      dp[i][j*A[i]]+=2
    if T < j*A[i]: break
print sorted(routing(dp,A,N-1,T,["-"]),reverse=True)[0].replace("-","")
0