Submission #399963

#TimeUsernameProblemLanguageResultExecution timeMemory
399963abc864197532Bomb (IZhO17_bomb)C++17
37 / 100
194 ms7624 KiB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define info() cerr << __PRETTY_FUNCTION__ << ": " << __LINE__ << endl
#define test(args...) info(), abc("[" + string(#args) + "]", args)
void abc() {cerr << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
    cerr << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
    while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
    return o >> a.X >> a.Y;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
    return o << '(' << a.X << ", " << a.Y << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
    bool is = false;
    for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
    return o << '}';
}
const int N = 1000087, logN = 20, K = 111;

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    string s[n];
    for (int i = 0; i < n; ++i) cin >> s[i];
    vector <int> cnt(m, 0), len(n + 1, 1 << 30);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cnt[j] = s[i][j] == '0' ? 0 : cnt[j] + 1;
        }
        vector <int> l(m), r(m);
        stack <int> stk;
        for (int j = 0; j < m; ++j) {
            if (!stk.empty() && cnt[stk.top()] >= cnt[j]) stk.pop();
            l[j] = stk.empty() ? j + 1 : j - stk.top();
            stk.push(j);
        }
        while (!stk.empty()) stk.pop();
        for (int j = m - 1; ~j; --j) {
            if (!stk.empty() && cnt[stk.top()] >= cnt[j]) stk.pop();
            r[j] = stk.empty() ? m - j : stk.top() - j;
            stk.push(j);
        }
        for (int j = 0; j < m; ++j) if (cnt[j] > 0) {
            len[cnt[j]] = min(len[cnt[j]], l[j] + r[j] - 1);
        }
    }
    int mn = n + 1;
    for (int j = 0; j < m; ++j) {
        int now = 0;
        for (int i = 0; i < n; ++i) {
            if (s[i][j] == '0') {
                if (now > 0) mn = min(mn, now);
                now = 0;
            }
            else now++;
        }
        if (now > 0) mn = min(mn, now);
    }
    if (mn == n + 1) mn = 0;
    int ans = 0;
    for (int i = 1; i <= mn; ++i) ans = max(ans, len[i] * i);
    cout << ans << endl;
}
/*
5 6
001000
111110
111110
111110
000100
 */
#Verdict Execution timeMemoryGrader output
Fetching results...