Submission #833542

#TimeUsernameProblemLanguageResultExecution timeMemory
833542vjudge1Bomb (IZhO17_bomb)C++17
12 / 100
1099 ms74000 KiB
#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 > 0) pref[i][j] += pref[i-1][j];
      if(j > 0) 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 > 0) ans -= pref[i1-1][j2];
    if(j1 > 0) ans -= pref[i2][j1-1];
    if(i1 > 0 && j1 > 0) ans += pref[i1-1][j1-1];
    return ans;
  };
  int ans = 0;
  vector b(n, vector<int>(m));
  for(int h = 1; h <= n; h++) {
    for(int w = 1; w <= m; w++) {
      debug(cerr << "h = " << h << " w = " << w << '\n');
      for(int i = 0; i+h-1 < n; i++) {
        for(int j = 0; j+h-1 < m; j++) {
          if(get(i, j, i+h-1, j+w-1) == h * w) {
            debug(cerr << i << ' ' << j << '\n');
            for(int ii = i; ii < i+h; ii++) {
              for(int jj = j; jj < j+w; jj++) {
                b[ii][jj] = 1;
              }
            }
          }
        }
      }
      if(a == b) ans = max(ans, h * w);
      debug({
        for(int i = 0; i+h-1 < n; i++) {
          for(int j = 0; j+w-1 < m; j++)
            cerr << b[i][j];
          cerr << '\n';
        }
      });
      for(int i = 0; i+h-1 < n; i++) {
        for(int j = 0; j+w-1 < 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 timeMemoryGrader output
Fetching results...