\ (\ large {example 1.} \) \ (\ large {\ text {2007} ZJOI board production} \)
\ (\\\)
\ (\ large {proof about the correctness of the practice, first of all if a rectangular area maximum, then it must withstand the boundary. then \\ update up, l, r if and only if a [i] [j] and a [i-1] [j ] satisfy a certain relationship between the remaining up, l no influence of r, it has no effect on the maximum matrix} \)
\ (\\\)
\ (\ Large \ Code textbf {:} \)
#include <bits/stdc++.h>
#define gc() getchar()
#define LL long long
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define _rep(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
const int N = 2e3 + 5;
int n, m, ans1, ans2, a[N][N], up[N][N], l[N][N], r[N][N];
inline int read() {
int x = 0, flg = 1;
char ch = gc();
while (!isdigit(ch)) ch = gc();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = gc();
return x * flg;
}
int main() {
n = read(), m = read();
rep(i, 1, n)
rep(j, 1, m) {
a[i][j] = read(); up[i][j] = 1;
l[i][j] = r[i][j] = j;
if (a[i][j] != a[i][j - 1] && j > 1) l[i][j] = l[i][j - 1];
}
rep(i, 1, n) _rep(j, m, 1) if (a[i][j] != a[i][j + 1] && j < m) r[i][j] = r[i][j + 1];
rep(i, 1, n)
rep(j, 1, m) {
if (i > 1 && a[i][j] != a[i - 1][j]) {
l[i][j] = max(l[i][j], l[i - 1][j]);
r[i][j] = min(r[i][j], r[i - 1][j]);
up[i][j] = up[i - 1][j] + 1;
}
int a = r[i][j] - l[i][j] + 1, b = min(up[i][j], a);
ans1 = max(ans1, b * b), ans2 = max(ans2, a * up[i][j]);
}
printf("%d\n%d\n", ans1, ans2);
return 0;
}
\ (\ large {example 2.} \) \ (\ large {jade moon} \)
\ (\\\)
\ (\ large {supra} practice \)
\ (\\\)
#include <bits/stdc++.h>
#define gc() getchar()
#define LL long long
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define _rep(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
const int N = 1e3 + 5;
int n, m, ans, up[N][N], l[N][N], r[N][N];
char a[N][N];
inline int read() {
int x = 0, flg = 1;
char ch = gc();
while (!isdigit(ch)) ch = gc();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = gc();
return x * flg;
}
int main() {
n = read(), m = read();
rep(i, 1, n)
rep(j, 1, m) {
cin >> a[i][j]; up[i][j] = 1;
l[i][j] = r[i][j] = j;
if (a[i][j] == a[i][j - 1] && a[i][j] == 'F' && j > 1) l[i][j] = l[i][j - 1];
}
rep(i, 1, n) _rep(j, m, 1) if (a[i][j] == a[i][j + 1] && a[i][j] == 'F' && j < m) r[i][j] = r[i][j + 1];
rep(i, 1, n)
rep(j, 1, m) {
if (i > 1 && a[i][j] == a[i - 1][j] && a[i][j] == 'F') {
l[i][j] = max(l[i][j], l[i - 1][j]);
r[i][j] = min(r[i][j], r[i - 1][j]);
up[i][j] = up[i - 1][j] + 1;
}
int a = r[i][j] - l[i][j] + 1;
ans = max(ans, a * up[i][j]);
}
printf("%d\n", ans * 3);
return 0;
}