結果

問題 No.2539 スライムゲーム
ユーザー ecotteaecottea
提出日時 2023-10-03 23:51:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 166 ms / 1,000 ms
コード長 1,025 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 20,992 KB
最終ジャッジ日時 2023-11-10 20:51:02
合計ジャッジ時間 3,891 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
9,984 KB
testcase_01 AC 30 ms
9,984 KB
testcase_02 AC 30 ms
9,984 KB
testcase_03 AC 29 ms
9,984 KB
testcase_04 AC 30 ms
9,984 KB
testcase_05 AC 29 ms
9,984 KB
testcase_06 AC 29 ms
9,984 KB
testcase_07 AC 29 ms
9,984 KB
testcase_08 AC 30 ms
9,984 KB
testcase_09 AC 30 ms
9,984 KB
testcase_10 AC 31 ms
9,984 KB
testcase_11 AC 30 ms
9,984 KB
testcase_12 AC 29 ms
9,984 KB
testcase_13 AC 29 ms
9,984 KB
testcase_14 AC 30 ms
9,984 KB
testcase_15 AC 29 ms
9,984 KB
testcase_16 AC 30 ms
9,984 KB
testcase_17 AC 30 ms
9,984 KB
testcase_18 AC 30 ms
9,984 KB
testcase_19 AC 30 ms
9,984 KB
testcase_20 AC 31 ms
9,984 KB
testcase_21 AC 31 ms
9,984 KB
testcase_22 AC 31 ms
9,984 KB
testcase_23 AC 30 ms
9,984 KB
testcase_24 AC 31 ms
9,984 KB
testcase_25 AC 29 ms
9,984 KB
testcase_26 AC 29 ms
9,984 KB
testcase_27 AC 31 ms
9,984 KB
testcase_28 AC 77 ms
11,776 KB
testcase_29 AC 95 ms
12,416 KB
testcase_30 AC 93 ms
20,992 KB
testcase_31 AC 30 ms
10,112 KB
testcase_32 AC 51 ms
10,112 KB
testcase_33 AC 166 ms
10,112 KB
testcase_34 AC 129 ms
12,288 KB
testcase_35 AC 136 ms
12,288 KB
testcase_36 AC 106 ms
12,800 KB
testcase_37 AC 106 ms
12,800 KB
testcase_38 AC 92 ms
20,992 KB
testcase_39 AC 94 ms
20,992 KB
testcase_40 AC 93 ms
20,992 KB
testcase_41 AC 93 ms
20,992 KB
testcase_42 AC 94 ms
20,992 KB
testcase_43 AC 93 ms
20,992 KB
testcase_44 AC 94 ms
20,992 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 truncated_pow(a, n):
    val = 1
    for _ in range(n):
        val *= a
        if val >= INF:
            return INF
    return val

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) + truncated_pow(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