# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
55483 | BThero | Bomb (IZhO17_bomb) | C++14 | 360 ms | 69920 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.
// Why I am so dumb? :c
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
short up[2502][2502];
short dw[2502][2502];
char s[2502][2502];
int f[2502];
int n, m, ans;
void solve() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; ++i) {
scanf("%s", s[i]);
}
int limh = n, limw = m;
for (int i = 0; i < n; ++i) {
int cur = 0;
for (int j = 0; j < m; ++j) {
if (s[i][j] == '1') {
++cur;
if (j + 1 == m || s[i][j + 1] == '0') {
limw = min(limw, cur);
}
}
else {
cur = 0;
}
}
}
for (int j = 0; j < m; ++j) {
int cur = 0;
for (int i = 0; i < n; ++i) {
if (s[i][j] == '1') {
up[i][j] = ++cur;
if (i + 1 == n || s[i + 1][j] == '0') {
limh = min(limh, cur);
}
}
else {
cur = 0;
}
}
}
for (int j = 0; j < m; ++j) {
int cur = 0;
for (int i = n - 1; i >= 0; --i) {
if (s[i][j] == '1') {
dw[i][j] = ++cur;
}
else {
cur = 0;
}
}
}
for (int i = 1; i <= limw; ++i) {
f[i] = limh;
}
for (int i = 0; i < n; ++i) {
int cur = 0;
short l = 10000, r = 10000;
for (int j = 0; j < m; ++j) {
if (s[i][j] == '1') {
++cur;
l = min(l, up[i][j]);
r = min(r, dw[i][j]);
f[cur] = min(f[cur], l + r - 1);
}
else {
cur = 0;
l = r = 10000;
}
}
}
for (int i = 0; i < n; ++i) {
int cur = 0;
short l = 10000, r = 10000;
for (int j = m - 1; j >= 0; --j) {
if (s[i][j] == '1') {
++cur;
l = min(l, up[i][j]);
r = min(r, dw[i][j]);
f[cur] = min(f[cur], l + r - 1);
}
else {
cur = 0;
l = r = 10000;
}
}
}
ans = f[1];
for (int i = 2; i <= limw; ++i) {
f[i] = min(f[i], f[i - 1]);
ans = max(ans, i * f[i]);
}
printf("%d\n", ans);
}
int main() {
//freopen("bomb.in", "r", stdin);
//freopen("bomb.out", "w", stdout);
int tt = 1;
while (tt--) {
solve();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |