結果
| 問題 |
No.708 (+ー)の式
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-07 16:26:14 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 789 bytes |
| コンパイル時間 | 398 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 67,584 KB |
| 最終ジャッジ日時 | 2024-07-03 09:29:06 |
| 合計ジャッジ時間 | 1,731 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 RE * 2 |
| other | AC * 2 RE * 10 |
ソースコード
import math
from math import sqrt
import sys
from collections import deque, defaultdict
from heapq import heappop, heappush
from copy import deepcopy
INF = 10 ** 18
MOD = 10 ** 9 + 7
MAX = 10 ** 5 + 7
mp=defaultdict(int)
def rec(t):
if len(t)==3:
a=t[0]-'0'
b=t[2]-'0'
if t[1]=='+': return a+b
else: return a-b
res=0
r=0
for i,c in enumerate(t):
if c=='+': r=0
elif c=='-': r=1
elif c=='(':
if r==0: res+=rec(t[i+1:mp[i]])
else : res-=rec(t[i+1:mp[i]])
else:
if r==0: res+=int(c)
else: res-=int(c)
return res
def main():
global s, mp
s=input()
st=()
for i,c in enumerate(s):
if c=='(':
st.append(i)
elif c==')':
mp[st.pop()]=i
print(rec(s))
if __name__ == '__main__':
main()