結果

問題 No.193 筒の数式
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-05-04 18:40:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 35 ms / 1,000 ms
コード長 678 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 82,332 KB
実行使用メモリ 54,088 KB
最終ジャッジ日時 2024-10-05 06:37:31
合計ジャッジ時間 1,572 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

def calc(s):
    s = "#" + s
    t = ""
    a = []
    op = []
    for i in range(1, len(s)):
        # 数字の直後の符号のみop
        if s[i] in ('+', '-') and s[i - 1].isdigit():
            op.append(s[i])
            a.append(t)
            t = ""
        else:
            t += s[i]
    if t != "":
        a.append(t)

    a = list(map(int, a))
    ans = a[0]
    for i in range(len(op)):
        if op[i] == '+':
            ans += a[i + 1]
        else:
            ans -= a[i + 1]

    return ans



s = input()
N = len(s)
s += s
ans = -10**15
for i in range(N):
    if s[i].isdigit() and s[i+N-1].isdigit():
        ans = max(ans, calc(s[i:i+N]))
print(ans)
0