比赛 CSP2023-J模拟赛 评测结果 AAAAAAAAAA
题目名称 复制题目 最终得分 100
用户昵称 zxhhh 运行时间 0.877 s
代码语言 C++ 内存使用 114.06 MiB
提交时间 2023-10-18 20:37:27
显示代码纯文本
#include <bits/stdc++.h>

using namespace std;
const int N = 305, M = 303; 
int n, m, f[N][N][N]; 
char s[N][N]; 

int main () {
    freopen("copy.in","r", stdin);
    freopen("copy.out", "w", stdout);  
    memset(f, -0x3f, sizeof(f)); 
    cin >> n >> m;
    for (int i = 1;i <= n;i++) cin >> (s[i]+1); 
    for (int i = 1;i <= n;i++) {
        for (int j = 1;j <= m;j++) {
            for (int z = 0;z <= 300;z++) {
                if (s[i][j] == '(') {
                    if (z) f[i][j][z] = max(f[i-1][j][z-1], f[i][j-1][z-1])-(i+j-1); 
                }
                else f[i][j][z] = max(f[i-1][j][z+1], f[i][j-1][z+1])+i+j-1; 
            }
            if (s[i][j] == '(') f[i][j][1] = max(f[i][j][1], -i-j+1);
        }
    }
    int ans = 0;
    for (int i = 1;i <= n;i++) for (int j = 1;j <= m;j++) ans = max(ans, f[i][j][0]); 
    cout << ans; 
    return 0;
}