# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
944678 | GrandTiger1729 | Bomb (IZhO17_bomb) | C++17 | 125 ms | 32176 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main()
{
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<string> g(n);
for (int i = 0; i < n; i++)
{
cin >> g[i];
}
int xx = INF, yy = INF;
{
for (int i = 0; i < n; i++)
{
int l = 0, r = 0;
while (l < m)
{
while (l < m && g[i][l] == '0')
{
l++;
}
if (l == m)
{
break;
}
r = l;
while (r < m && g[i][r] == '1')
{
r++;
}
xx = min(xx, r - l);
l = r;
}
}
for (int j = 0; j < m; j++)
{
int l = 0, r = 0;
while (l < n)
{
while (l < n && g[l][j] == '0')
{
l++;
}
if (l == n)
{
break;
}
r = l;
while (r < n && g[r][j] == '1')
{
r++;
}
yy = min(yy, r - l);
l = r;
}
}
}
vector<int> res(yy, xx);
auto solve = [&]()
{
vector<vector<int>> rr(n, vector<int>(m));
for (int i = 0; i < n; i++)
{
int cur = m;
for (int j = m - 1; j >= 0; j--)
{
if (g[i][j] == '0')
{
cur = j;
}
rr[i][j] = cur;
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (g[i][j] == '1' && (i == 0 || g[i - 1][j] == '0') && (j == 0 || g[i][j - 1] == '0'))
{
int k = i, cur = INF;
while (k < n && k - i < res.size() && g[k][j] == '1')
{
cur = min(cur, rr[k][j] - j);
res[k - i] = min(res[k - i], cur);
k++;
}
res.resize(k - i);
}
}
}
};
for (int tt = 0; tt < 2; tt++)
{
solve();
reverse(g.begin(), g.end());
solve();
for (int i = 0; i < n; i++)
{
reverse(g[i].begin(), g[i].end());
}
}
int ans = 0;
for (int i = 0; i < res.size(); i++)
{
ans = max(ans, (i + 1) * res[i]);
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |