Pagini recente » Cod sursa (job #2663217) | Cod sursa (job #1208070) | Cod sursa (job #2730591) | Cod sursa (job #2436202) | Cod sursa (job #1823207)
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define pii pair<int, int>
#define mp make_pair
using namespace std;
const string name = "bmatrix",
in_file = name + ".in",
out_file = name + ".out";
ifstream fin(in_file);
ofstream fout(out_file);
const int MAX = 205;
int n, m;
int matrix[MAX][MAX];
int heights[MAX][MAX];
vector<int> stackk;
int lefty[MAX], righty[MAX];
int dp[MAX][MAX];
void build_heights(int line) {
memset(heights, 0, sizeof(heights));
for (int i = line + 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (matrix[i][j]) {
heights[i][j] = 0;
} else {
heights[i][j] = heights[i - 1][j] + 1;
}
}
}
for (int i = 1; i <= line; i++) {
for (int j = 1; j <= m; j++) {
if (matrix[i][j]) {
heights[i][j] = 0;
} else {
heights[i][j] = heights[i - 1][j] + 1;
}
}
}
}
int go(int x1, int y1, int x2, int y2) {
int maxx = 0;
for (int i = x1; i <= x2; i++) {
stackk.clear();
stackk.push_back(0);
heights[i][0] = -1;
for (int j = y1; j <= y2; j++) {
int height = heights[i][j];
while (!stackk.empty() && heights[i][stackk.back()] >= height) {
stackk.pop_back();
}
lefty[j] = stackk.back();
stackk.push_back(j);
}
stackk.clear();
stackk.push_back(m + 1);
heights[i][m + 1] = -1;
for (int j = y2; j > 0; j--) {
int height = heights[i][j];
while (!stackk.empty() && heights[i][stackk.back()] >= height) {
stackk.pop_back();
}
righty[j] = stackk.back();
stackk.push_back(j);
}
for (int j = y1; j <= y2; j++) {
dp[i][j] = heights[i][j] * (righty[j] - lefty[j] - 1);
maxx = max(dp[i][j], maxx);
}
}
return maxx;
}
int main() {
fin >> n >> m;
string str;
for (int i = 1; i <= n; i++) {
fin >> str;
for (int j = 1; j <= m; j++) {
matrix[i][j] = str[j - 1] - '0';
}
}
int result = 0;
for (int line = 1; line < n; line++) {
build_heights(line);
int topLeftSecond = line + 1, bottomRightFirst = line;
result = max(result, go(1, 1, bottomRightFirst, m) +
go (topLeftSecond, 1, n, m));
}
fout << result;
return 0;
}