結果

問題 No.708 (+ー)の式
ユーザー eQeeQe
提出日時 2020-05-07 16:26:14
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 789 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 87,068 KB
実行使用メモリ 78,836 KB
最終ジャッジ日時 2023-09-16 07:58:12
合計ジャッジ時間 3,579 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
72,892 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 110 ms
73,168 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 109 ms
72,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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()



0