結果

問題 No.193 筒の数式
ユーザー rpy3cpprpy3cpp
提出日時 2015-04-28 00:59:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,391 bytes
コンパイル時間 77 ms
コンパイル使用メモリ 10,988 KB
実行使用メモリ 7,984 KB
最終ジャッジ日時 2023-09-18 13:57:17
合計ジャッジ時間 1,318 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,956 KB
testcase_01 AC 16 ms
7,984 KB
testcase_02 AC 16 ms
7,864 KB
testcase_03 AC 17 ms
7,976 KB
testcase_04 AC 17 ms
7,924 KB
testcase_05 AC 17 ms
7,964 KB
testcase_06 AC 17 ms
7,808 KB
testcase_07 AC 16 ms
7,856 KB
testcase_08 AC 17 ms
7,860 KB
testcase_09 AC 16 ms
7,980 KB
testcase_10 AC 17 ms
7,920 KB
testcase_11 WA -
testcase_12 AC 17 ms
7,828 KB
testcase_13 AC 17 ms
7,788 KB
testcase_14 AC 16 ms
7,968 KB
testcase_15 AC 18 ms
7,856 KB
testcase_16 AC 17 ms
7,844 KB
testcase_17 AC 17 ms
7,860 KB
testcase_18 AC 17 ms
7,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_valid_eq(eq):
    if eq.startswith('+'):
        return False
    if eq.startswith('-'):
        return False
    if eq.endswith('+'):
        return False
    if eq.endswith('-'):
        return False
    if '+-' in eq:
        return False
    if '-+' in eq:
        return False
    if '++' in eq:
        return False
    if '--' in eq:
        return False
    return True

def remove_leading_zeros(eq):
    while eq.startswith('0'):
        eq = eq[1:]
    prev_length = len(eq) + 1
    while len(eq) < prev_length:
        prev_length = len(eq)
        eq = eq.replace('+0', '+')
        eq = eq.replace('-0', '-')
    prev_length = len(eq) + 1
    while len(eq) < prev_length:
        prev_length = len(eq)
        eq = eq.replace('++', '+')
        eq = eq.replace('+-', '-')
        eq = eq.replace('-+', '+')
        eq = eq.replace('--', '-')
    if eq.endswith('-'):
        eq = eq[:-1]
    if eq.endswith('+'):
        eq = eq[:-1]
    return eq
    

def find_max(S):
    max_val = -float('inf')
    for i in range(len(S)):
        eq = S[i:] + S[:i]
        if not is_valid_eq(eq):
            continue
        eq = remove_leading_zeros(eq)
        if len(eq) == 0:
            continue
        try:
            val = eval(eq)            
        except:
            val = max_val
        max_val = max(val, max_val)
    return max_val

S = input()
print(find_max(S))
0