Submission #169905

#TimeUsernameProblemLanguageResultExecution timeMemory
169905stefdascaBomb (IZhO17_bomb)C++14
42 / 100
50 ms12280 KiB
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9

using namespace std;

typedef long long ll;


int add(int a, int b)
{
    ll x = a+b;
    if(x >= mod)
        x -= mod;
    if(x < 0)
        x += mod;
    return x;
}
ll mul(ll a, ll b)
{
    return (a*b) % mod;
}

ll pw(ll a, ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b & 1)
            ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed()
{
    long long a = rng();
    return a;
}
char c[2600][2600];
int mars[2600][2600], sp[2600][2600];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; ++i)
        cin >> (c[i] + 1);
    int xx = 0;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
            xx += (c[i][j] == '0');
    if(!xx)
    {
        cout << n*m;
        return 0;
    }
    int mnx = m, mny = n;
    for(int i = 1; i <= n; ++i)
    {
        int str = 0;
        for(int j = 1; j <= m; ++j)
        {
            if(c[i][j] == '1')
                ++str;
            else
            {
                if(str)
                    mnx = min(mnx, str);
                str = 0;
            }
        }
        if(str)
            mnx = min(mnx, str);
    }
    for(int j = 1; j <= m; ++j)
    {
        int str = 0;
        for(int i = 1; i <= n; ++i)
        {
            if(c[i][j] == '1')
                ++str;
            else
            {
                if(str)
                    mny = min(mny, str);
                str = 0;
            }
        }
        if(str)
            mny = min(mny, str);
    }
    if(n <= 200 && m <= 200)
    {
        for(int i = 1; i <= n; ++i)
        {
            for(int j = 1; j <= m; ++j)
            {
                sp[i][j] = (c[i][j] - '0') + sp[i-1][j] + sp[i][j-1] - sp[i-1][j-1];
            }
        }
        int mxans = 0;
        for(int i = mny; i >= 1; --i)
            for(int j = mnx; j >= 1; --j)
            {
                if(i*j <= mxans)
                    continue;
                for(int q = i; q <= n; ++q)
                    for(int p = j; p <= m; ++p)
                    {
                        if(sp[q][p] - sp[q - i][p] - sp[q][p - j] + sp[q - i][p - j] == i * j)
                        {
                            mars[q - i + 1][p - j + 1]++;
                            mars[q + 1][p - j + 1]--;
                            mars[q - i + 1][p + 1]--;
                            mars[q + 1][p + 1]++;
                        }
                    }
                bool ok = 1;
                for(int q = 1; q <= n; ++q)
                    for(int p = 1; p <= m; ++p)
                    {
                        mars[q][p] = mars[q][p] + mars[q-1][p] + mars[q][p-1] - mars[q-1][p-1];
                        if(c[q][p] == '1' && !mars[q][p])
                        {
                            ok = 0;
                            p = m+1;
                            q = n+1;
                        }
                    }
                for(int q = 1; q <= n; ++q)
                    for(int p = 1; p <= m; ++p)
                        mars[q][p] = 0;
                if(ok)
                    mxans = max(mxans, i*j);
            }
        cout << mxans;
    }
    else
        cout << mnx * mny;
    return 0;
}

Compilation message (stderr)

bomb.cpp: In function 'int main()':
bomb.cpp:131:38: warning: assuming signed overflow does not occur when assuming that (X + c) >= X is always true [-Wstrict-overflow]
                     for(int p = 1; p <= m; ++p)
                                    ~~^~~~
bomb.cpp:131:38: warning: assuming signed overflow does not occur when assuming that (X + c) >= X is always true [-Wstrict-overflow]
#Verdict Execution timeMemoryGrader output
Fetching results...