记录编号 583629 评测结果 AAAAAAAAAA
题目名称 复制题目 最终得分 100
用户昵称 Gravataryrtiop 是否通过 通过
代码语言 C++ 运行时间 1.633 s
提交时间 2023-10-19 20:20:14 内存使用 222.29 MiB
显示代码纯文本
#include <bits/stdc++.h>
#define pb emplace_back
#define fir first
#define sec second

using i64 = long long;
using pii = std::pair<int, int>;

constexpr int maxn = 305;
int f[maxn][maxn][maxn << 1];
char s[maxn][maxn];
int n, m;

int main() {
	freopen("copy.in", "r", stdin);
	freopen("copy.out", "w", stdout);
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i)
		scanf("%s", s[i] + 1);
	memset(f, 0xcf, sizeof(f));
	for (int i = 0; i <= n; ++i)
		f[i][0][0] = 0;
	for (int j = 0; j <= m; ++j)
		f[0][j][0] = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j) {
			if (s[i][j] == '(')
				f[i][j][1] = 1;
			for (int k = 0; k <= n + m; ++k) {
				if (s[i][j] == '(') {
					if (!k) continue ;
					f[i][j][k] = std::max(f[i - 1][j][k - 1], f[i][j - 1][k - 1]) + k;
				} else {
					f[i][j][k] = std::max(f[i - 1][j][k + 1], f[i][j - 1][k + 1]) + k;
				}
			}
		}
	int ans = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			ans = std::max(ans, f[i][j][0]);
	printf("%d\n", ans);
	return 0;
}