# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
833193 | vjudge1 | Bomb (IZhO17_bomb) | C++17 | 1097 ms | 73976 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');
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;
};
vector b(n, vector<int>(m));
const int INF = 1e9;
int ans = 0;
for(int h = 1; h <= n; h++) {
debug(cerr << "h = " << h << '\n');
int best = INF;
for(int i = 0; i+h-1 < n; i++) {
int consec = 0;
for(int j = 0; j < m; j++) {
int x = (get(i, j, i+h-1, j) == h);
debug(cerr << x);
if(x) {
consec++;
for(int k = i; k < i+h; k++)
b[k][j] = 1;
} else {
if(consec != 0) best = min(best, consec);
consec = 0;
}
}
if(consec != 0) best = min(best, consec);
debug(cerr << '\n');
}
debug(cerr << "best = " << best << '\n');
if(best != INF && a == b) ans = max(ans, best * h);
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++)
b[i][j] = 0;
}
}
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... |