結果

問題 No.2539 スライムゲーム
ユーザー ecotteaecottea
提出日時 2023-10-04 00:02:46
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 871 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 122,144 KB
最終ジャッジ日時 2023-11-10 20:51:11
合計ジャッジ時間 5,720 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
63,656 KB
testcase_01 AC 51 ms
63,656 KB
testcase_02 AC 51 ms
63,656 KB
testcase_03 AC 55 ms
63,656 KB
testcase_04 RE -
testcase_05 AC 51 ms
63,656 KB
testcase_06 AC 52 ms
63,656 KB
testcase_07 AC 51 ms
63,656 KB
testcase_08 AC 51 ms
63,656 KB
testcase_09 AC 50 ms
63,656 KB
testcase_10 AC 51 ms
63,656 KB
testcase_11 AC 51 ms
63,656 KB
testcase_12 AC 52 ms
63,656 KB
testcase_13 AC 51 ms
63,656 KB
testcase_14 AC 51 ms
63,656 KB
testcase_15 AC 50 ms
63,656 KB
testcase_16 AC 50 ms
63,656 KB
testcase_17 AC 51 ms
63,656 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 50 ms
63,656 KB
testcase_21 AC 53 ms
63,912 KB
testcase_22 AC 53 ms
63,912 KB
testcase_23 AC 50 ms
63,656 KB
testcase_24 AC 54 ms
66,028 KB
testcase_25 AC 51 ms
63,656 KB
testcase_26 AC 50 ms
63,656 KB
testcase_27 RE -
testcase_28 AC 149 ms
85,996 KB
testcase_29 AC 155 ms
87,976 KB
testcase_30 AC 186 ms
122,140 KB
testcase_31 AC 52 ms
63,656 KB
testcase_32 AC 52 ms
64,040 KB
testcase_33 RE -
testcase_34 AC 155 ms
87,848 KB
testcase_35 RE -
testcase_36 AC 168 ms
88,432 KB
testcase_37 AC 167 ms
88,748 KB
testcase_38 AC 190 ms
122,012 KB
testcase_39 AC 189 ms
122,012 KB
testcase_40 AC 186 ms
122,012 KB
testcase_41 AC 188 ms
122,012 KB
testcase_42 AC 190 ms
122,012 KB
testcase_43 AC 185 ms
122,128 KB
testcase_44 AC 185 ms
122,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import re
import sys

sys.setrecursionlimit(10**5)

content = input()
pattern = r'^([\(\)]+)$'
result = re.match(pattern, content)

if not result:
    sys.exit("format error.")

s = content

n = len(s)
if n <= 0 or 10**5 < n:
    sys.exit("S")

INF = 10**18 + 1


def sep(l, r):
    acc = 0
    i = r - 1
    while i >= l:
        if s[i] == ')':
            acc += 1
        else:
            acc -= 1
        if acc == 0:
            return i
        if acc < 0:
            return -1
        i -= 1
    return -1


def solve(l, r, dep):
    if dep >= 6:
        return INF
    
    if l >= r:
        return 0
    
    m = sep(l, r)
    if m == -1:
        return 1
    
    val = solve(l, m, dep) + 2**solve(m + 1, r - 1, dep + 1)
    if val >= INF:
        return INF
    
    return val

res = solve(0, n, 0)

if res >= INF:
    print("INFTY")
else:
    print(res)
0