結果
問題 | No.297 カードの数式 |
ユーザー |
![]() |
提出日時 | 2023-07-08 23:59:22 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,225 bytes |
コンパイル時間 | 209 ms |
コンパイル使用メモリ | 82,260 KB |
実行使用メモリ | 54,296 KB |
最終ジャッジ日時 | 2024-07-22 20:16:51 |
合計ジャッジ時間 | 2,248 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 7 WA * 16 |
ソースコード
n = int(input())a = list(input().split())d = {'+':0,'-':0}aa = []for i in a:if i == '+' or i == '-':d[i] += 1else:aa.append(int(i))dd = d.copy()aa.sort()ans1=aa[0]now = 1for i in aa[1:]:if dd['+'] + dd['-'] == 1:t = []while now < len(aa):t.append(str(aa[now]))now += 1t=t[::-1]t = int(''.join(t))if dd['+'] == 1:ans1 += telse:ans1 -= tbreakif dd['+'] > 0:ans1 += idd['+' ] -= 1else:ans1 -= idd['-'] -= 1now += 1if dd['+'] + dd['-'] == 1:t = []while now < len(aa):t.append(str(aa[now]))now += 1t=t[::-1]t = int(''.join(t))if dd['+'] == 1:ans1 += telse:ans1 -= tbreakaa.sort(reverse = True)ans = aa[0]cnt = d['+'] + d['-']tt = n-1ans = aa[0]now = 1while len(aa) > now and tt > cnt + 1:ans = ans * 10 + aa[now]now += 1tt -=1for i in aa[now:]:if d['+'] > 0:ans += idd['+' ] -= 1else:ans -= iprint(ans,ans1)