結果

問題 No.2456 Stamp Art
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-08-03 00:10:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 438 ms / 5,000 ms
コード長 1,310 bytes
コンパイル時間 2,885 ms
コンパイル使用メモリ 209,840 KB
実行使用メモリ 42,348 KB
最終ジャッジ日時 2023-09-02 11:16:36
合計ジャッジ時間 10,565 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 352 ms
42,328 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 385 ms
42,332 KB
testcase_07 AC 376 ms
42,204 KB
testcase_08 AC 336 ms
42,348 KB
testcase_09 AC 383 ms
42,188 KB
testcase_10 AC 416 ms
42,248 KB
testcase_11 AC 366 ms
42,268 KB
testcase_12 AC 372 ms
42,304 KB
testcase_13 AC 438 ms
42,208 KB
testcase_14 AC 428 ms
42,280 KB
testcase_15 AC 338 ms
42,324 KB
testcase_16 AC 168 ms
22,832 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 214 ms
29,412 KB
testcase_20 AC 383 ms
42,248 KB
testcase_21 AC 365 ms
35,636 KB
testcase_22 AC 400 ms
42,244 KB
testcase_23 AC 14 ms
5,184 KB
testcase_24 AC 29 ms
6,228 KB
testcase_25 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int H, W;
vector<vector<int>> v;
vector<string> S;

bool solve(int X){
    vector<vector<int>> w(H+2, vector<int>(W+2));
    for (int i=1; i<=H-X+1; i++){
        for (int j=1; j<=W-X+1; j++){
            if (v[i+X-1][j+X-1]-v[i+X-1][j-1]-v[i-1][j+X-1]+v[i-1][j-1] == X*X){
                w[i][j]++; w[i+X][j]--; w[i][j+X]--; w[i+X][j+X]++;
            }
        }
    }

    for (int i=0; i<=H; i++){
        for (int j=1; j<=W; j++){
            w[i][j] += w[i][j-1];
        }
    }

    for (int i=1; i<=H; i++){
        for (int j=0; j<=W; j++){
            w[i][j] += w[i-1][j];
        }
    }

    for (int i=1; i<=H; i++){
        for (int j=1; j<=W; j++){
            if (S[i-1][j-1] == '#' && w[i][j] == 0) return 0;
        }
    }
    return 1;
}

int main(){

    cin >> H >> W;
    S.resize(H);
    for (int i=0; i<H; i++) cin >> S[i];
    v.resize(H+1, vector<int>(W+1));

    for (int i=1; i<=H; i++){
        for (int j=1; j<=W; j++){
            if (S[i-1][j-1] == '#') v[i][j]++;
            v[i][j] += v[i-1][j] + v[i][j-1] - v[i-1][j-1];
        }
    }

    int l=1, r=min(H, W)+1, c;
    while(r-l>1){
        c = (r+l)/2;
        if (solve(c)) l=c;
        else r=c;
    }

    cout << l << endl;

    return 0;
}
0