Submission #1128786

#TimeUsernameProblemLanguageResultExecution timeMemory
1128786farni4kBomb (IZhO17_bomb)C++20
7 / 100
68 ms6548 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=2501;
char c[N][N];
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m; cin>>n>>m;
    for (int i = 1; i<=n; i++) {
        for (int j = 1; j<=m; j++) {
            cin>>c[i][j];
        }
    }

    int mxx=1e9,mxy=1e9;
    for (int i = 1; i<=m; i++) {
        int st=-1,end=-1,mxst=-1,mxend=-1;
        for (int j = 1; j<=n; j++) {
            if (c[j][i]=='1') {
                if (st==-1) st=j;
                else if (end==-1 && j==n) {
                    end=j;
                    if ((end-st+1)>(mxend-mxst+1) || (mxst==-1 && mxend==-1)) {
                        mxend=end;
                        mxst=st;
                    }
                    end=-1;
                    st=-1;
                }
            } else {
                if (end==-1 && st!=-1) {
                    end=j-1;
                    if ((end-st+1)>(mxend-mxst+1) || (mxst==-1 && mxend==-1)) {
                        mxend=end;
                        mxst=st;
                    }
                    end=-1;
                    st=-1;
                }
            }
        }
        if (mxst==-1 && mxend==-1 && st>0 && end>0) {
            mxend=end;
            mxst=st;
        }
        if ((mxend-mxst+1)<mxy && mxst!=-1 && mxend!=-1) mxy=mxend-mxst+1;
    }

    for (int i = 1; i<=n; i++) {
        int st=-1,end=-1,mxst=-1,mxend=-1;
        for (int j = 1; j<=m; j++) {
            if (c[i][j]=='1') {
                if (st==-1) st=j;
                else if (end==-1 && j==m) {
                    end=j;
                    if ((end-st+1)>(mxend-mxst+1) || (mxst==-1 && mxend==-1)) {
                        mxend=end;
                        mxst=st;
                    }
                    end=-1;
                    st=-1;
                }
            } else {
                if (end==-1 && st!=-1) {
                    end=j-1;
                    if ((end-st+1)>(mxend-mxst+1) || (mxst==-1 && mxend==-1)) {
                        mxend=end;
                        mxst=st;
                    }
                    end=-1;
                    st=-1;
                }
            }
        }
        if (mxst==-1 && mxend==-1 && st>0 && end>0) {
            mxend=end;
            mxst=st;
        }
        // cout<<st<<' '<<end<<'\n';
        if ((mxend-mxst+1)<mxx && mxst!=-1 && mxend!=-1) mxx=mxend-mxst+1;
    }
    if (mxx==1e9) mxx=1;
    if (mxy==1e9) mxy=1;
    cout<<mxx*mxy;
}
#Verdict Execution timeMemoryGrader output
Fetching results...