結果

問題 No.2456 Stamp Art
ユーザー hourenhouren
提出日時 2023-09-01 22:58:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 510 ms / 5,000 ms
コード長 1,581 bytes
コンパイル時間 1,942 ms
コンパイル使用メモリ 173,652 KB
実行使用メモリ 38,964 KB
最終ジャッジ日時 2024-06-11 18:02:06
合計ジャッジ時間 9,525 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL << 62), MOD = 998244353;
constexpr int INF = (1 << 30);

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    vector<vector<int>> sum(h+1,vector<int>(w+1,0));
    rep(i,h){
        cin >> s[i];
        rep(j,w){
            sum[i+1][j+1] = sum[i][j+1] + sum[i+1][j] - sum[i][j] + (s[i][j]=='#');
        }
    }
    int ok = 1, ng = min(h,w)+1;
    while(ng-ok>1){
        int md = (ok+ng)/2;
        vector<vector<int>> imos(h+1,vector<int>(w+1,0));
        for(int i=0;i<=h-md;i++)for(int j=0;j<=w-md;j++){
            if(sum[i+md][j+md]-sum[i][j+md]-sum[i+md][j]+sum[i][j]==md*md){
                imos[i][j]++;
                imos[i][j+md]--;
                imos[i+md][j]--;
                imos[i+md][j+md]++;
            }
        }
        rep(i,h+1)rep(j,w) imos[i][j+1] += imos[i][j];
        rep(i,h)rep(j,w+1) imos[i+1][j] += imos[i][j];
        bool f = true;
        rep(i,h)rep(j,w){
            if((s[i][j]=='#')!=(imos[i][j]!=0)) f = false, i = h, j = w;
        }
        if(f) ok = md;
        else ng = md;
    }
    cout << ok << '\n';
    return 0;
}
0