Submission #170220

#TimeUsernameProblemLanguageResultExecution timeMemory
170220theboatmanBomb (IZhO17_bomb)C++17
24 / 100
48 ms7672 KiB
#include <bits/stdc++.h>

#define y1 theboatman
#define make_struct(args...) {args}

using namespace std;
typedef long long ll;

const long long INF = ll(1e18) + 10;
const int inf = int(1e9) + 10;
const int N = int(1e6) + 10;

bool can(int first, int c, int n, int m, vector <string> &a) {
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if (a[i][j] == '1') {
                int sz = 0;
                while(j < m && a[i][j] == '1') {
                    j++;
                    sz++;
                }
                j--;

                if (sz < c) {
                    return false;
                }
            }
        }
    }

    for(int j = 0; j < m; j++) {
        for(int i = 0; i < n; i++) {
            if (a[i][j] == '1') {
                int sz = 0;
                while(i < n && a[i][j] == '1') {
                    i++;
                    sz++;
                }
                i--;

                if (sz < first) {
                    return false;
                }
            }
        }
    }

    return true;
}

void brute(int n, int m) {
    vector <string> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        int first = i;

        if (!can(i, 1, n, m, a)) {
            continue;
        }

        int l = 1, r = m + 1;
        while(l < r) {
            int c = l + r >> 1;
            if (can(first, c, n, m, a)) {
                l = c + 1;
            }
            else {
                r = c;
            }
        }

        l--;
        ans = max(ans, 1LL * first * l);
    }
    cout << ans << "\n";
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    int n, m;
    cin >> n >> m;

    if (1LL * n * m * n * 5 <= int(5e7)) {
        brute(n, m);
        return 0;
    }

    vector <string> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int second = m;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if (a[i][j] == '1') {
                int sz = 0;
                while(j < m && a[i][j] == '1') {
                    j++;
                    sz++;
                }
                j--;

                second = min(second, sz);
            }
        }
    }

    int first = n;
    for(int j = 0; j < m; j++) {
        for(int i = 0; i < n; i++) {
            if (a[i][j] == '1') {
                int sz = 0;
                while(i < n && a[i][j] == '1') {
                    i++;
                    sz++;
                }
                i--;

                first = min(first, sz);
            }
        }
    }

    cout << 1LL * first * second << "\n";
    return 0;
}
/*
*/

Compilation message (stderr)

bomb.cpp: In function 'void brute(int, int)':
bomb.cpp:67:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
             int c = l + r >> 1;
                     ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...