結果

問題 No.297 カードの数式
ユーザー pluto77pluto77
提出日時 2016-02-14 11:01:12
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 745 bytes
コンパイル時間 63 ms
コンパイル使用メモリ 7,112 KB
実行使用メモリ 6,452 KB
最終ジャッジ日時 2023-10-22 05:07:48
合計ジャッジ時間 1,920 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,452 KB
testcase_01 AC 11 ms
6,452 KB
testcase_02 AC 10 ms
6,452 KB
testcase_03 AC 11 ms
6,452 KB
testcase_04 WA -
testcase_05 RE -
testcase_06 WA -
testcase_07 AC 11 ms
6,452 KB
testcase_08 AC 11 ms
6,452 KB
testcase_09 RE -
testcase_10 AC 11 ms
6,452 KB
testcase_11 AC 11 ms
6,452 KB
testcase_12 RE -
testcase_13 AC 12 ms
6,452 KB
testcase_14 AC 11 ms
6,452 KB
testcase_15 AC 11 ms
6,452 KB
testcase_16 WA -
testcase_17 AC 10 ms
6,452 KB
testcase_18 AC 11 ms
6,452 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 11 ms
6,452 KB
testcase_23 RE -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#coding: utf-8
##yuki_297
import sys

n=int(raw_input())
s=raw_input().split()
ls=list(s)
ls.sort()

cnt_plus=ls.count('+')
cnt_minus=ls.count('-')
cnt=cnt_plus+cnt_minus
cnt_plus2=cnt_plus
cnt_minus2=cnt_minus

while ls[0]=='+' or ls[0]=='-':
 del ls[0]
while ls[0]=='0':
 del ls[0]

ls.reverse()
ls2=ls[:]

#max
res=0
while cnt_minus>0:
 res+=-int(ls.pop())
 cnt_minus-=1
while cnt_plus>0:
 res+=int(ls.pop())
 cnt_plus-=1
lsn=int("".join(ls))
res1=res+lsn

#min
res=0
if cnt_minus2==0:
 res2=res1
 print res1,res2
 sys.exit()

if cnt_minus2>0:
 res+=int(ls2.pop())
 cnt_minus2-=1
while cnt_plus2>0:
 res+=int(ls2.pop())
 cnt_plus2-=1
while cnt_minus2>0:
 res-=int(ls2.pop())
 cnt_minus2-=1
lsn=-int("".join(ls2))
res2=res+lsn
print res1,res2
0