結果

問題 No.297 カードの数式
ユーザー titiatitia
提出日時 2022-11-01 03:44:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 17 ms / 1,000 ms
コード長 946 bytes
コンパイル時間 650 ms
コンパイル使用メモリ 10,964 KB
実行使用メモリ 8,372 KB
最終ジャッジ日時 2023-09-23 00:09:23
合計ジャッジ時間 2,370 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,316 KB
testcase_01 AC 16 ms
8,232 KB
testcase_02 AC 17 ms
8,248 KB
testcase_03 AC 16 ms
8,192 KB
testcase_04 AC 16 ms
8,316 KB
testcase_05 AC 16 ms
8,272 KB
testcase_06 AC 16 ms
8,312 KB
testcase_07 AC 16 ms
8,184 KB
testcase_08 AC 16 ms
8,204 KB
testcase_09 AC 16 ms
8,196 KB
testcase_10 AC 16 ms
8,368 KB
testcase_11 AC 16 ms
8,188 KB
testcase_12 AC 16 ms
8,124 KB
testcase_13 AC 16 ms
8,344 KB
testcase_14 AC 16 ms
8,344 KB
testcase_15 AC 16 ms
8,296 KB
testcase_16 AC 16 ms
8,372 KB
testcase_17 AC 17 ms
8,344 KB
testcase_18 AC 16 ms
8,340 KB
testcase_19 AC 16 ms
8,312 KB
testcase_20 AC 17 ms
8,180 KB
testcase_21 AC 16 ms
8,352 KB
testcase_22 AC 16 ms
8,304 KB
testcase_23 AC 16 ms
8,292 KB
testcase_24 AC 16 ms
8,184 KB
testcase_25 AC 17 ms
8,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import permutations

n=int(input())
C=input().split()

A=[]
P=0
M=0

for c in C:
    if c =="+":
        P+=1
    elif c=="-":
        M+=1
    else:
        A.append(c)

A.sort(reverse=True)

P1=P
M1=M

l=len(A)-P-M
S=A[:l]

for x in range(l,len(A)):
    if P1>0:
        P1-=1
        S.append("+")
    elif M1>0:
        M1-=1
        S.append("-")

    S.append(A[x])


MAX=eval("".join(S))

if M>0:
    P1=P
    M1=M

    l=len(A)-P-M
    S=["-"]+A[:l]
    M1-=1

    for x in range(l,len(A)):
        if M1>0:
            M1-=1
            S=["-"]+[A[x]]+S
        elif P1>0:
            P1-=1
            S=["+"]+[A[x]]+S
        else:
            S=[A[x]]+S

    MIN=eval("".join(S))
    
else:
    wake=P+1
    K=["" for i in range(wake)]

    A.sort()

    for i in range(len(A)):
        K[i%len(K)]=K[i%len(K)]+A[i]

    MIN=0

    for k in K:
        MIN+=int(k)

print(MAX,MIN)
        
    


                

    
0