Analysis; [Deep version of HDU 1506] Every input row, updating the height once becomes a problem of question 1505. [Deep version of HDU 2870]
[Cpp]
# Include <iostream>
# Include <string>
# Include <cstring>
# Include <algorithm>
# Include <cstdio>
# Include <cmath>
Using namespace std;
Int h [1005], L [1005], R [1005];
Int main (){
Int T; cin> T;
While (T --){
Int n, m; cin> n> m;
Getchar ();
Memset (h, 0, sizeof (h ));
Int maxs = 0;
For (int I = 1; I <= n; ++ I ){
For (int j = 1; j <= m; ++ j ){
Char a; cin>;
If (a = 'F') ++ h [j];
Else h [j] = 0;
L [j] = R [j] = j;
Getchar ();
}
For (int j = 1, k = m; j <= m; ++ j, -- k ){
While (L [j]> 1 & h [L [j]-1]> = h [j])
L [j] = L [L [j]-1];
While (R [k] <m & h [R [k] + 1]> = h [k])
R [k] = R [R [k] + 1];
}
For (int j = 1; j <= m; ++ j ){
Int s = h [j] * (R [j]-L [j] + 1 );
Maxs = max (maxs, s );
}
}
Cout <3 * maxs <endl;
}
Return 0;
}
# Include <iostream>
# Include <string>
# Include <cstring>
# Include <algorithm>
# Include <cstdio>
# Include <cmath>
Using namespace std;
Int h [1005], L [1005], R [1005];
Int main (){
Int T; cin> T;
While (T --){
Int n, m; cin> n> m;
Getchar ();
Memset (h, 0, sizeof (h ));
Int maxs = 0;
For (int I = 1; I <= n; ++ I ){
For (int j = 1; j <= m; ++ j ){
Char a; cin>;
If (a = 'F') ++ h [j];
Else h [j] = 0;
L [j] = R [j] = j;
Getchar ();
}
For (int j = 1, k = m; j <= m; ++ j, -- k ){
While (L [j]> 1 & h [L [j]-1]> = h [j])
L [j] = L [L [j]-1];
While (R [k] <m & h [R [k] + 1]> = h [k])
R [k] = R [R [k] + 1];
}
For (int j = 1; j <= m; ++ j ){
Int s = h [j] * (R [j]-L [j] + 1 );
Maxs = max (maxs, s );
}
}
Cout <3 * maxs <endl;
}
Return 0;
}