結果

問題 No.193 筒の数式
ユーザー HachimoriHachimori
提出日時 2015-04-27 00:25:42
言語 Python2
(2.7.18)
結果
AC  
実行時間 11 ms / 1,000 ms
コード長 769 bytes
コンパイル時間 733 ms
コンパイル使用メモリ 6,664 KB
実行使用メモリ 6,124 KB
最終ジャッジ日時 2023-09-18 12:26:38
合計ジャッジ時間 1,363 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,056 KB
testcase_01 AC 10 ms
6,124 KB
testcase_02 AC 11 ms
6,088 KB
testcase_03 AC 10 ms
6,000 KB
testcase_04 AC 10 ms
5,876 KB
testcase_05 AC 10 ms
5,880 KB
testcase_06 AC 11 ms
5,928 KB
testcase_07 AC 10 ms
6,056 KB
testcase_08 AC 11 ms
5,856 KB
testcase_09 AC 11 ms
5,852 KB
testcase_10 AC 11 ms
5,884 KB
testcase_11 AC 10 ms
5,944 KB
testcase_12 AC 11 ms
5,860 KB
testcase_13 AC 10 ms
5,852 KB
testcase_14 AC 10 ms
5,972 KB
testcase_15 AC 10 ms
5,856 KB
testcase_16 AC 11 ms
6,052 KB
testcase_17 AC 11 ms
5,852 KB
testcase_18 AC 11 ms
5,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python
#coding:utf8

def read():
    return raw_input()


def calc(expr):
    ret = 0
    idx = 0
    
    expr = '+' + expr
    while idx < len(expr):
        isAdd = expr[idx] == '+'
        idx += 1

        num = ''
        while idx < len(expr) and expr[idx].isdigit():
             num += expr[idx]
             idx += 1

        if isAdd:
            ret += int(num)
        else:
            ret -= int(num)

    return ret

    
def work(s):
    ans = -(1 << 30)

    for L in range(len(s)):
        expr = s[L:] + s[:L]

        if expr[0]  == '+' or expr[0]  == '-' or \
           expr[-1] == '+' or expr[-1] == '-':
           continue
        
        ans = max(ans, calc(expr))

    print ans


if __name__ == "__main__":
    work(read())
0