# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100577 | alexpetrescu | Bomb (IZhO17_bomb) | C++14 | 541 ms | 60280 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 <cstdio>
#include <algorithm>
//FILE *fin = fopen("a.in", "r"), *fout = fopen("a.out", "w");
#define fin stdin
#define fout stdout
#define MAXN 2500
int left[MAXN + 2][MAXN + 2], right[MAXN + 2][MAXN + 2];
int d[MAXN + 2];
char m[MAXN + 2][MAXN + 10];
int nrlin, nrcol;
inline void solve() {
for (int i = 1; i <= nrlin; i++) {
left[i][0] = 0;
for (int j = 1; j <= nrcol; j++)
if (m[i][j] == '1')
left[i][j] = left[i][j - 1];
else
left[i][j] = j;
right[i][nrcol + 1] = nrcol + 1;
for (int j = nrcol; j > 0; j--)
if (m[i][j] == '1')
right[i][j] = right[i][j + 1];
else
right[i][j] = j;
for (int j = 1; j <= nrcol; j++)
if (m[i][j] == '1')
d[1] = std::min(d[1], right[i][j] - left[i][j] - 1);
}
for (int j = 1; j <= nrcol; j++) {
int st = 0, dr = nrcol + 1, cat = 0;
for (int i = 1; i <= nrlin; i++) {
if (m[i][j] == '1') {
st = std::max(st, left[i][j]);
dr = std::min(dr, right[i][j]);
cat++;
d[cat] = std::min(d[cat], dr - st - 1);
} else {
if (cat)
d[cat + 1] = 0;
st = 0, dr = nrcol + 1;
cat = 0;
}
}
if (cat)
d[cat + 1] = 0;
}
}
int main() {
fscanf(fin, "%d%d ", &nrlin, &nrcol);
for (int i = 1; i <= nrlin; i++)
fgets(m[i] + 1, MAXN + 5, fin), d[i] = nrcol;
solve();
for (int i = 1; i <= nrlin / 2; i++)
for (int j = 1; j <= nrcol; j++)
std::swap(m[i][j], m[nrlin - i + 1][j]);
solve();
for (int i = 2; i <= nrlin; i++)
d[i] = std::min(d[i], d[i - 1]);
int ans = d[1];
for (int i = 2; i <= nrlin; i++)
ans = std::max(ans, i * d[i]);
fprintf(fout, "%d\n", ans);
fclose(fin);
fclose(fout);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |