結果

問題 No.10 +か×か
ユーザー nsd_fb
提出日時 2015-02-19 06:31:49
言語 Python2
(2.7.18)
結果
AC  
実行時間 2,227 ms / 5,000 ms
コード長 788 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 53,316 KB
最終ジャッジ日時 2024-12-14 15:27:22
合計ジャッジ時間 6,109 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

n = input()
total = input()
a = map(int, raw_input().split())

dic = {a[0]:''}

for value in a[1:]:
    next_dic = {}

    for key, operators in dic.iteritems():
        next_key = key + value

        if next_key <= total:
            next_operators = operators + '+'

            if next_key in next_dic:
                next_dic[next_key] = max(next_dic[next_key], next_operators)
            else:
                next_dic[next_key] = next_operators

        next_key = key * value
        if next_key <= total:
            next_operators = operators + '*'

            if next_key in next_dic:
                next_dic[next_key] = max(next_dic[next_key], next_operators)
            else:
                next_dic[next_key] = next_operators
    
    dic = next_dic

print dic[total]
0