結果

問題 No.297 カードの数式
ユーザー lllllll88938494lllllll88938494
提出日時 2023-07-08 23:59:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,225 bytes
コンパイル時間 2,259 ms
コンパイル使用メモリ 86,976 KB
実行使用メモリ 71,612 KB
最終ジャッジ日時 2023-09-30 02:22:38
合計ジャッジ時間 5,603 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 70 ms
71,436 KB
testcase_02 AC 69 ms
71,256 KB
testcase_03 WA -
testcase_04 AC 70 ms
71,412 KB
testcase_05 AC 71 ms
71,388 KB
testcase_06 WA -
testcase_07 AC 71 ms
71,456 KB
testcase_08 AC 70 ms
71,264 KB
testcase_09 AC 70 ms
71,504 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 70 ms
71,512 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 74 ms
71,428 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(input().split())
d = {'+':0,'-':0}
aa = []

for i in a:
    if i ==  '+' or  i == '-':
        d[i] += 1
    else:
        aa.append(int(i))

dd = d.copy()
aa.sort()
ans1=aa[0]
now = 1
for i in aa[1:]:
    if dd['+'] + dd['-'] == 1:
        t = []
        while now < len(aa):
            t.append(str(aa[now]))
            now += 1
        t=t[::-1]
        t = int(''.join(t))
        if dd['+'] == 1:
            ans1 += t
        else:
            ans1 -= t
        break
            
    if dd['+'] > 0:
        ans1 += i
        dd['+' ] -= 1
    else:
        ans1 -= i
        dd['-'] -= 1
    now += 1
    if dd['+'] + dd['-'] == 1:
        t = []
        while now < len(aa):
            t.append(str(aa[now]))
            now += 1
        t=t[::-1]
        t = int(''.join(t))
        if dd['+'] == 1:
            ans1 += t
        else:
            ans1 -= t
        break
            

aa.sort(reverse = True)
ans = aa[0]
cnt = d['+'] + d['-']
tt = n-1
ans = aa[0]
now = 1
while len(aa) > now and tt > cnt + 1:
    ans = ans * 10 + aa[now]
    now += 1
    tt -=1
for i in aa[now:]:
    if d['+'] > 0:
        ans += i
        dd['+' ] -= 1
    else:
        ans -= i
 
print(ans,ans1)
0