結果

問題 No.10 +か×か
ユーザー nsd_fbnsd_fb
提出日時 2015-02-19 06:31:49
言語 Python2
(2.7.18)
結果
AC  
実行時間 2,385 ms / 5,000 ms
コード長 788 bytes
コンパイル時間 107 ms
コンパイル使用メモリ 6,624 KB
実行使用メモリ 52,804 KB
最終ジャッジ日時 2023-08-21 06:10:22
合計ジャッジ時間 6,640 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,988 KB
testcase_01 AC 11 ms
6,044 KB
testcase_02 AC 11 ms
5,976 KB
testcase_03 AC 2,325 ms
51,800 KB
testcase_04 AC 25 ms
8,228 KB
testcase_05 AC 12 ms
5,960 KB
testcase_06 AC 2,385 ms
52,804 KB
testcase_07 AC 674 ms
31,800 KB
testcase_08 AC 111 ms
18,468 KB
testcase_09 AC 70 ms
14,284 KB
testcase_10 AC 11 ms
5,996 KB
testcase_11 AC 11 ms
5,992 KB
権限があれば一括ダウンロードができます

ソースコード

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