# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1036536 | adaawf | Bomb (IZhO17_bomb) | C++17 | 94 ms | 55888 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 <iostream>
using namespace std;
char a[2505][2505];
int f[2505][2505], g[2505][2505], d[2505];
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
d[j] = n;
cin >> a[i][j];
if (a[i][j] == '1') f[i][j] = f[i - 1][j] + 1;
else f[i][j] = 0;
}
}
for (int i = n; i >= 1; i--) {
for (int j = 1; j <= m; j++) {
if (a[i][j] == '1') g[i][j] = g[i + 1][j] + 1;
else g[i][j] = 0;
if (a[i][j] == '1') {
d[1] = min(d[1], f[i][j] + g[i][j] - 1);
}
}
}
int ma = m;
for (int i = 1; i <= n; i++) {
int h = n, k = n, c = 0;
for (int j = 1; j <= m; j++) {
if (a[i][j] == '1') {
c++;
h = min(h, f[i][j]);
k = min(k, g[i][j]);
d[c] = min(d[c], h + k - 1);
}
else {
if (c != 0) ma = min(ma, c);
c = 0;
h = k = n;
}
}
if (c != 0) ma = min(ma, c);
h = k = n;
c = 0;
for (int j = m; j >= 1; j--) {
if (a[i][j] == '1') {
c++;
h = min(h, f[i][j]);
k = min(k, g[i][j]);
d[c] = min(d[c], h + k - 1);
}
else {
if (c != 0) ma = min(ma, c);
c = 0;
h = k = n;
}
}
if (c != 0) ma = min(ma, c);
}
int res = -1e9;
for (int i = 1; i <= ma; i++) {
res = max(res, i * d[i]);
}
cout << res;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |