結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 657 ms
42,668 KB
testcase_01 AC 477 ms
42,796 KB
testcase_02 AC 475 ms
42,796 KB
testcase_03 AC 483 ms
42,796 KB
testcase_04 AC 486 ms
42,796 KB
testcase_05 AC 485 ms
42,796 KB
testcase_06 AC 484 ms
42,796 KB
testcase_07 AC 485 ms
42,796 KB
testcase_08 AC 479 ms
42,796 KB
testcase_09 AC 478 ms
42,796 KB
testcase_10 AC 480 ms
42,796 KB
testcase_11 AC 475 ms
42,796 KB
testcase_12 AC 470 ms
42,796 KB
testcase_13 AC 472 ms
42,796 KB
testcase_14 AC 476 ms
42,796 KB
testcase_15 AC 472 ms
42,796 KB
testcase_16 AC 474 ms
42,796 KB
testcase_17 AC 481 ms
42,796 KB
testcase_18 AC 468 ms
42,796 KB
testcase_19 AC 472 ms
42,796 KB
testcase_20 AC 477 ms
42,796 KB
testcase_21 AC 472 ms
42,796 KB
testcase_22 AC 475 ms
42,796 KB
testcase_23 AC 471 ms
42,796 KB
testcase_24 AC 479 ms
42,796 KB
testcase_25 AC 483 ms
42,796 KB
testcase_26 AC 481 ms
42,796 KB
testcase_27 AC 474 ms
42,796 KB
testcase_28 AC 528 ms
44,204 KB
testcase_29 AC 555 ms
44,716 KB
testcase_30 AC 544 ms
52,908 KB
testcase_31 AC 477 ms
42,796 KB
testcase_32 AC 502 ms
42,796 KB
testcase_33 AC 618 ms
42,796 KB
testcase_34 AC 579 ms
44,716 KB
testcase_35 AC 588 ms
44,716 KB
testcase_36 AC 564 ms
45,100 KB
testcase_37 AC 552 ms
45,100 KB
testcase_38 AC 547 ms
52,780 KB
testcase_39 AC 544 ms
52,780 KB
testcase_40 AC 539 ms
52,780 KB
testcase_41 AC 533 ms
52,780 KB
testcase_42 AC 542 ms
52,780 KB
testcase_43 AC 544 ms
52,908 KB
testcase_44 AC 534 ms
81,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import re
import sys
import numpy as np # 無意味

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