結果
問題 |
No.2539 スライムゲーム
|
ユーザー |
|
提出日時 | 2023-10-04 00:02:46 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 871 bytes |
コンパイル時間 | 255 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 121,728 KB |
最終ジャッジ日時 | 2024-09-26 00:55:05 |
合計ジャッジ時間 | 6,743 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 39 RE * 6 |
ソースコード
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)