結果
問題 | No.297 カードの数式 |
ユーザー |
![]() |
提出日時 | 2023-07-09 00:02:55 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,229 bytes |
コンパイル時間 | 211 ms |
コンパイル使用メモリ | 82,344 KB |
実行使用メモリ | 54,436 KB |
最終ジャッジ日時 | 2024-07-22 20:20:35 |
合計ジャッジ時間 | 2,174 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 11 WA * 12 |
ソースコード
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 - cntans = 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)