結果

問題 No.297 カードの数式
ユーザー MitI_7
提出日時 2015-11-30 18:17:45
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 35 ms / 1,000 ms
コード長 777 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-12-26 02:24:25
合計ジャッジ時間 1,835 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import zip_longest


def main():
    n = input()
    l = input().split()
    num = sorted([int(i) for i in l if i.isnumeric()])
    ope = sorted([i for i in l if not i.isnumeric()])

    nums = [x for x in num[:len(ope)]]
    nums.append(int("".join(map(str, sorted(num[len(ope):], reverse=True)))))
    max_ans = eval("".join([str(a) + b for a, b in zip_longest(sorted(nums, reverse=True), ope, fillvalue='')]))
    min_ans = eval("".join([str(a) + b for a, b in zip_longest(sorted(nums), ope, fillvalue='')]))

    if '-' not in ope:
        l = ["" for i in range(len(ope) + 1)]
        for i, x in enumerate(num):
            l[i % len(l)] += str(x)

        min_ans = sum(map(int, l))

    print(max_ans, min_ans)
    
if __name__ == '__main__':
    main()
0