Submission #1128733

#TimeUsernameProblemLanguageResultExecution timeMemory
1128733VietnowBomb (IZhO17_bomb)C++20
24 / 100
1101 ms98320 KiB
#include <bits/stdc++.h>
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define int long long
#define ff first
#define ss second
#define pb push_back
#define y1 zildjian
#define left radio
#define right head
 
using namespace std;
 
const int N = 2501;
const int INF = 1e18;
const int mod = 1e9+7;
const int mod1 = 998244353;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,m;
int a[N][N];
int del[N][N];

bool available(int w, int h, int i, int j){
    if(i+w-1 > n) return 0;
    if(j+h-1 > m) return 0;
    for(int k = i;k<i+w;k++){
        for(int l = j;l<j+h;l++){
            if(!a[k][l]) return 0;
        }
    }
    return 1;
}

void upd(int w, int h, int i, int j){
    for(int k = i;k<i+w;k++){
        for(int l = j;l<j+h;l++){
            del[k][l] = 1;
        }
    }
}

void clear_del(){
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            del[i][j] = 0;
        }
    }
}

bool check(int w, int h){
    // cout<<w<<' '<<h<<'\n';
    clear_del();
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            if(a[i][j]){
                // cout<<w<<' '<<h<<' '<<i<<' '<<j<<' '<<available(w,h,i,j)<<'\n';
                if(!available(w,h,i,j)){
                    continue;
                }
                else{
                    upd(w,h,i,j);
                }
            }
        }
    }
    bool ok = 1;
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            if(a[i][j] && !del[i][j]){
                ok = 0;
                break;
            }
        }
        if(!ok) break;
    }
    return ok;
}

bool ok(int ar){
    for(int w = 1;w*w<=ar;w++){
        if(ar%w == 0){
            int h = ar/w;
            if(check(w,h)) return 1;
            if(check(h,w)) return 1;
        }
    }
    return 0;
}

void solve(){
    cin>>n>>m;
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            char x;
            cin>>x;
            a[i][j] = x-'0';
        }
    }
    int ans;
    for(int i = 1;i<=n*m;i++){
        if(ok(i)) ans = i;
    }
    cout<<ans<<'\n';
}


signed main(){
    // freopen("bootfall.in","r",stdin); 
    // freopen("bootfall.out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    // cout.tie(nullptr);
    int t = 1;
    // cin>>t;
    for(int i = 1;i<=t;i++){
        // cout<<"Case "<<i<<": ";
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...