# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
423303 | antimirage | Bomb (IZhO17_bomb) | C++14 | 734 ms | 74844 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.
/*
* let's for fixed width X find the maximum valid height Y, denote it by ans[X].
* upper bound of Y for every X is ans[1].
*
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <assert.h>
using namespace std;
int main() {
int n, m, res = 0;
cin >> n >> m;
vector <vector <int>> a(n + 5, vector<int>(m + 5, 0));
for (int i = 1; i <= n; i++) {
scanf("\n");
for (int j = 1; j <= m; j++) {
char ch;
scanf("%c", &ch);
a[i][j] = ch - 48;
}
}
vector <vector <int>> up(n + 5, vector<int>(m + 5, 0));
vector <vector <int>> dn(n + 5, vector<int>(m + 5, 0));
for (int j = 1; j <= m; j++) {
for (int i = 1; i <= n; i++) {
up[i][j] = a[i][j] ? up[i - 1][j] + 1 : 0;
}
for (int i = n; i >= 1; i--) {
dn[i][j] = a[i][j] ? dn[i + 1][j] + 1 : 0;
}
}
vector <int> ans(m + 5, n);
for (int t = 0; t < 2; t++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i][j])
ans[1] = min(ans[1], up[i][j] + dn[i][j] - 1);
}
for (int j = 1; j <= m; j++) {
if (a[i][j] && !a[i][j - 1]) {
int min_d = n, min_u = n, k;
for (k = j; a[i][k]; k++) {
min_d = min(min_d, dn[i][k]);
min_u = min(min_u, up[i][k]);
ans[k - j + 1] = min(ans[k - j + 1], min_d + min_u - 1);
}
ans[k - j + 1] = 0;
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j + j <= m; j++) {
swap(a[i][j], a[i][m - j + 1]);
swap(up[i][j], up[i][m - j + 1]);
swap(dn[i][j], dn[i][m - j + 1]);
}
}
}
for (int i = 1; i <= m; i++) {
ans[i] = min(ans[i], ans[i - 1]);
res = max(res, i * ans[i]);
//cout << i << " --> " << ans[i] << endl;
}
cout << res << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |