結果

問題 No.2456 Stamp Art
ユーザー hourenhouren
提出日時 2023-09-01 22:58:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 490 ms / 5,000 ms
コード長 1,581 bytes
コンパイル時間 1,605 ms
コンパイル使用メモリ 173,128 KB
実行使用メモリ 38,960 KB
最終ジャッジ日時 2023-09-02 11:19:20
合計ジャッジ時間 9,542 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 490 ms
38,752 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 483 ms
38,860 KB
testcase_07 AC 334 ms
38,960 KB
testcase_08 AC 240 ms
38,888 KB
testcase_09 AC 366 ms
38,756 KB
testcase_10 AC 377 ms
38,736 KB
testcase_11 AC 418 ms
38,936 KB
testcase_12 AC 269 ms
38,756 KB
testcase_13 AC 471 ms
38,828 KB
testcase_14 AC 367 ms
38,856 KB
testcase_15 AC 445 ms
38,700 KB
testcase_16 AC 236 ms
21,008 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 277 ms
26,964 KB
testcase_20 AC 352 ms
38,876 KB
testcase_21 AC 377 ms
35,400 KB
testcase_22 AC 407 ms
38,860 KB
testcase_23 AC 13 ms
5,044 KB
testcase_24 AC 27 ms
6,092 KB
testcase_25 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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