結果

問題 No.708 (+ー)の式
ユーザー k0jumpk0jump
提出日時 2018-06-30 06:33:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 967 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 8,604 KB
最終ジャッジ日時 2023-09-13 16:11:10
合計ジャッジ時間 1,236 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,536 KB
testcase_01 AC 18 ms
8,496 KB
testcase_02 AC 19 ms
8,484 KB
testcase_03 AC 19 ms
8,600 KB
testcase_04 AC 18 ms
8,464 KB
testcase_05 AC 18 ms
8,488 KB
testcase_06 AC 18 ms
8,584 KB
testcase_07 AC 17 ms
8,488 KB
testcase_08 AC 17 ms
8,556 KB
testcase_09 WA -
testcase_10 AC 17 ms
8,604 KB
testcase_11 AC 18 ms
8,552 KB
testcase_12 WA -
testcase_13 AC 17 ms
8,568 KB
testcase_14 AC 18 ms
8,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
s = input()
total = 0
done = [0]*len(s)
lefts,rights = deque(),deque()

#get ( ) position
for i in range(len(s)):
    if s[i] == '(':
        lefts.append(i)
    elif s[i] == ')':
        rights.append(i)

#calc in ( )
while 0 < len(lefts):
    l = lefts.popleft()
    r = rights.popleft()
    done[l-1],done[l],done[r] = 1,1,1
    tmp = 0
    sign = '+'
    for j in range(l+1,r):
        done[j] = 1
        if s[j] == '+' or s[j] == '-':
            sign = s[j]
        else:
            if sign == '+':
                tmp += int(s[j])
            else:
                tmp -= int(s[j])
    if s[l-1] == '+':
        total += tmp
    else:
        total -= tmp

#calc all
sign = '+'
for x in range(len(s)):
    if done[x] == 0:
        if s[x] == '+' or s[x] == '-':
            sign = s[x]
        else:
            if sign == '+':
                total += int(s[x])
            else:
                total -= int(s[x])
print(total)
0