#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define PB push_back
#define MP make_pair
#define all(x) x.begin(),x.end()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N = 310;
const int oo = 2e9;
char c[N][N];
short f[N][N][N], ans = 0, n, m;
void upd(short &x, short y){
x = max(x, y);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> c[n - 1 - i][j];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
for (int sm = 0; sm <= i; sm++)
f[i][j][sm] = -1;
for (int j = 0; j < m; j++)
if (c[0][j] == 'M')
f[0][j][0] = 0;
for (int i = 0; i < n - 1; i++)
for (int j = 0; j < m; j++)
for (int sm = 0; sm <= i; sm++){
if (f[i][j][sm] < 0) continue;
for (int stp = -1; stp < 2; stp++){
int ni = i + 1, nj = j + stp;
if (nj < 0 || nj >= m) continue;
if (c[ni][nj] == '*'){
upd(ans, f[i][j][sm]);
} else if (c[ni][nj] == '.'){
upd(f[ni][nj][sm], f[i][j][sm]);
} else if (c[ni][nj] == '('){
upd(f[ni][nj][sm + 1], f[i][j][sm] + 1);
} else if (sm > 0){
upd(f[ni][nj][sm - 1], f[i][j][sm] + 1);
}
}
}
for (int j = 0; j < m; j++)
for (int sm = 0; sm < n; sm++)
ans = max(ans, f[n - 1][j][sm]);
cout << ans << '\n';
for (int i = ans / 2; i > 0; i--)
cout << "()";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
2 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
3 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
4 |
Incorrect |
4 ms |
640 KB |
Output isn't correct |
5 |
Partially correct |
5 ms |
1280 KB |
Partially correct |
6 |
Incorrect |
7 ms |
3456 KB |
Output isn't correct |
7 |
Incorrect |
7 ms |
4992 KB |
Output isn't correct |
8 |
Incorrect |
6 ms |
2688 KB |
Output isn't correct |
9 |
Partially correct |
8 ms |
5120 KB |
Partially correct |
10 |
Incorrect |
10 ms |
6784 KB |
Output isn't correct |
11 |
Incorrect |
66 ms |
52480 KB |
Output isn't correct |
12 |
Partially correct |
64 ms |
52344 KB |
Partially correct |
13 |
Incorrect |
34 ms |
23680 KB |
Output isn't correct |
14 |
Incorrect |
33 ms |
23680 KB |
Output isn't correct |
15 |
Incorrect |
76 ms |
55920 KB |
Output isn't correct |
16 |
Incorrect |
70 ms |
55808 KB |
Output isn't correct |
17 |
Incorrect |
66 ms |
47104 KB |
Output isn't correct |
18 |
Incorrect |
61 ms |
47096 KB |
Output isn't correct |
19 |
Incorrect |
78 ms |
56056 KB |
Output isn't correct |
20 |
Incorrect |
71 ms |
56056 KB |
Output isn't correct |