# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
833207 | vjudge1 | Bomb (IZhO17_bomb) | C++17 | 1099 ms | 74032 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;
// using ld = long double;
#define all(x) begin(x), end(x)
#ifdef LOCAL
#define debug(...) __VA_ARGS__;
#else
#define debug(...)
#endif
template<class A, class B> ostream& operator<<(ostream& os, const pair<A, B> &p);
template<class T> ostream& operator<<(ostream& os, const vector<T> &v);
template<class T, size_t N> ostream& operator<<(ostream& os, const array<T, N> &v);
template<class A, class B>
ostream& operator<<(ostream& os, const pair<A, B> &p) {
return os << '(' << p.first << ',' << p.second << ')';
}
template<class T>
ostream& operator<<(ostream& os, const vector<T> &v) {
os << '{'; bool fs = 1;
for(auto &i : v) { if(!fs) os << ','; os << i; fs = 0; }
return os << '}';
}
template<class T, size_t N>
ostream& operator<<(ostream& os, const array<T, N> &v) {
os << '{'; bool fs = 1;
for(auto &i : v) { if(!fs) os << ','; os << i; fs = 0; }
return os << '}';
}
void init() {
}
void solve(int tt = 0) {
int n, m; cin >> n >> m;
vector a(n, vector<int>(m));
bool ok = 0;
for(auto &v : a) for(int &i : v) {
char c; cin >> c;
i = c - '0';
ok |= i;
}
if(!ok) return void(cout << 0 << '\n');
int h = 1e9, w = 1e9;
{
vector b = a;
for(int i = 1; i < n; i++) {
for(int j = 0; j < m; j++) {
if(b[i][j] != 0) {
b[i][j] += b[i-1][j];
}
}
}
debug({
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++)
cerr << b[i][j];
cerr << '\n';
}
});
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) if(b[i][j] != 0 && (i == n-1 || (i < n-1 && b[i+1][j] == 0))) {
h = min(h, b[i][j]);
}
}
}
vector pref(n, vector<int>(m));
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
pref[i][j] = a[i][j];
if(i) pref[i][j] += pref[i-1][j];
if(j) pref[i][j] += pref[i][j-1];
if(i > 0 && j > 0) pref[i][j] -= pref[i-1][j-1];
}
}
const auto get = [&](int i1, int j1, int i2, int j2) -> int {
int ans = pref[i2][j2];
if(i1) ans -= pref[i1-1][j2];
if(j1) ans -= pref[i2][j1-1];
if(i1 && j1) ans += pref[i1-1][j1-1];
return ans;
};
int ans = 0;
vector b(n, vector<int>(m));
for(int hh = 1; hh <= h; hh++) {
for(int i = 0; i+hh-1 < n; i++) {
for(int j = 0; j < m; j++) {
b[i][j] = (get(i, j, i+hh-1, j) == hh);
}
}
for(int j = 1; j < m; j++) {
for(int i = 0; i+hh-1 < n; i++) {
b[i][j] += b[i][j-1];
}
}
for(int i = 0; i+hh-1 < n; i++) {
for(int j = 0; j < m; j++) if(b[i][j] != 0 && (j == m-1 || (j < m-1 && b[i][j+1] == 0))) {
ans = max(ans, h * w);
w = min(w, b[i][j]);
}
}
}
cout << ans << '\n';
}
void reset() {
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; // cin >> t;
init();
for(int i = 1; i <= t; i++) solve(i), reset();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |