Submission #169921

#TimeUsernameProblemLanguageResultExecution timeMemory
169921stefdascaBomb (IZhO17_bomb)C++14
68 / 100
784 ms59000 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 n, m, mars[2600][2600], sp[2600][2600];
int sum(int xa, int ya, int xb, int yb)
{
    return sp[xb][yb] - sp[xa - 1][yb] - sp[xb][ya - 1] + sp[xa - 1][ya - 1];
}
bool chk(int i, int j)
{
    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;
    return ok;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    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;
    }
    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];
    if(n <= 450 && m <= 450)
    {
        int mxans = 0;
        for(int i = n; i >= 1; --i)
        {
            int st = mxans / i + 1;
            int dr = m;
            if(st > dr)
                break;
            int ans = 0;
            if(chk(i, st))
                while(st <= dr)
                {
                    int mid = (st + dr) / 2;
                    if(chk(i, mid))
                        ans = mid, st = mid + 1;
                    else
                        dr = mid - 1;
                }
            mxans = max(mxans, i * ans);
        }
        cout << mxans;
    }
    else
    {
        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);
        }
        int mxans = 0;
        // mnx * some number
        int st = 1;
        int dr = mny;
        int ans = 1;
        while(st <= dr)
        {
            int mid = (st + dr) / 2;
            if(chk(mid, mnx))
                ans = mid, st = mid + 1;
            else
                dr = mid - 1;
        }
        mxans = max(mxans, ans * mnx);
        st = 1;
        dr = mnx;
        ans = 1;
        while(st <= dr)
        {
            int mid = (st + dr) / 2;
            if(chk(mny, mid))
                ans = mid, st = mid + 1;
            else
                dr = mid - 1;
        }
        mxans = max(mxans, mny * ans);
        cout << mxans;
    }
    return 0;
}

Compilation message (stderr)

bomb.cpp: In function 'bool chk(int, int)':
bomb.cpp:70:26: 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)
                        ~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...