Submission #334542

#TimeUsernameProblemLanguageResultExecution timeMemory
334542beksultan04Bomb (IZhO17_bomb)C++14
100 / 100
457 ms78060 KiB
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define pb push_back
#define endi puts("");
const int N = 1e5+12,INF=1e9+7;
int q[2505][2505],dp[N],up[2505][2505],down[2505][2505],ans[N];

main(){
    int n,m,i,j,X=INF,Y=INF;
    cin>>n>>m;
    for (i=1;i<=n;++i)
        for (j=1;j<=m;++j){
            char ch;
            cin>>ch;
            q[i][j]=ch-'0';
        }


    for (i=1;i<=n;++i){
        for (j=1;j<=m;++j){
            if (q[i][j]){
                up[i][j] = 1+up[i-1][j];
            }
        }
    }
    for (i=n;i>0;--i){
        for (j=1;j<=m;++j){
            if (q[i][j]){
                down[i][j] = 1+down[i+1][j];
                if (q[i-1][j] == 0)X = min(X,down[i][j]);
            }
        }
    }
/// /// /// ///
    for (i=1;i<=m;++i){
        ans[i]=X;
    }
    for (i=1;i<=n;++i){
        int a=INF,b=INF,c=0;
        for (j=1;j<=m;++j){
            if (q[i][j] == 0){
                if (c != 0)
                X = min(X,c);
                a=b=INF;
                c=0;
            }
            else {
                a = min(a,down[i][j]);
                b = min(b,up[i][j]);
                c++;
                ans[c] = min(ans[c],b+a-1);
            }
        }


        a=INF,b=INF,c=0;
        for (j=m;j>0;--j){
            if (q[i][j] == 0){
                if (c != 0)
                Y    = min(Y,c);
                a=b=INF;
                c=0;
            }
            else {
                a = min(a,down[i][j]);
                b = min(b,up[i][j]);
                c++;
                ans[c] = min(ans[c],b+a-1);
            }
        }
        if (c > 0)
            Y = min(Y,c);
    }

/// /// /// ///
    int mx = 0;

    for (i=1;i<=Y;++i){
        mx = max(mx,ans[i]*i);
    }
    cout <<mx;


}




Compilation message (stderr)

bomb.cpp:18:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   18 | main(){
      |      ^
#Verdict Execution timeMemoryGrader output
Fetching results...