# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1030368 | caterpillow | Bomb (IZhO17_bomb) | C++17 | 114 ms | 1312 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;
using ll = long long;
#define vt vector
#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, b) FOR(i, 0, b)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define pb push_back
#define endl '\n'
#ifndef LOCAL
#define cerr if (0) std::cerr
#endif
/*
N^3: find max width for each given height
*/
int rs, cs;
vt<vt<bool>> grid;
vt<vt<int>> sfx;
int sum(int r1, int c1, int r2, int c2) {
return sfx[r1][c1] - sfx[r1][c2 + 1] - sfx[r2 + 1][c1] + sfx[r2 + 1][c2 + 1];
}
int mx(int h) {
cerr << "\nchecking " << h << endl;
// find longest run
vt<vt<bool>> mod(rs - h + 1, vt<bool>(cs));
F0R (r, rs - h + 1) {
F0R (c, cs) {
mod[r][c] = sum(r, c, r + h - 1, c) == h;
}
}
int mn = cs;
F0R (r, rs - h + 1) {
int streak = 0;
F0R (c, cs) {
if (mod[r][c]) streak++;
else if (streak) mn = min(mn, streak), streak = 0;
}
}
return mn;
}
main() {
cin.tie(0)->sync_with_stdio();
cin >> rs >> cs;
if (rs > 450 || cs > 450) return 0;
rs += 2, cs += 2;
grid.resize(rs, vt<bool>(cs));
sfx.resize(rs + 1, vt<int>(cs + 1));
FOR (r, 1, rs - 1) {
FOR (c, 1, cs - 1) {
char ch; cin >> ch;
grid[r][c] = sfx[r][c] = ch - '0';
}
}
ROF (r, 0, rs) ROF (c, 0, cs) sfx[r][c] += sfx[r][c + 1];
ROF (r, 0, rs) ROF (c, 0, cs) sfx[r][c] += sfx[r + 1][c];
// calculate maximum height
int mxh = rs;
F0R (c, cs) {
int streak = 0;
F0R (r, rs) {
if (grid[r][c]) streak++;
else if (streak) mxh = min(mxh, streak), streak = 0;
}
}
cerr << "maximum height " << mxh << endl;
int ans = 0;
FOR (h, 1, mxh + 1) {
ans = max(ans, h * mx(h));
}
cout << ans << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |