結果

問題 No.2456 Stamp Art
ユーザー ochiaigawaochiaigawa
提出日時 2023-09-01 23:45:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 348 ms / 5,000 ms
コード長 1,547 bytes
コンパイル時間 2,914 ms
コンパイル使用メモリ 206,056 KB
実行使用メモリ 38,960 KB
最終ジャッジ日時 2023-09-02 11:21:28
合計ジャッジ時間 10,580 ms
ジャッジサーバーID
(参考情報)
judge16 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 239 ms
38,720 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 282 ms
38,748 KB
testcase_07 AC 300 ms
38,864 KB
testcase_08 AC 275 ms
38,960 KB
testcase_09 AC 306 ms
38,860 KB
testcase_10 AC 342 ms
38,960 KB
testcase_11 AC 270 ms
38,860 KB
testcase_12 AC 304 ms
38,860 KB
testcase_13 AC 348 ms
38,904 KB
testcase_14 AC 348 ms
38,764 KB
testcase_15 AC 242 ms
38,784 KB
testcase_16 AC 120 ms
20,900 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 160 ms
26,920 KB
testcase_20 AC 313 ms
38,856 KB
testcase_21 AC 299 ms
35,408 KB
testcase_22 AC 321 ms
38,904 KB
testcase_23 AC 10 ms
5,052 KB
testcase_24 AC 24 ms
6,036 KB
testcase_25 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0); cout.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for(int i = 0; i < H; i++) {
    cin >> S[i];
  }
  vector<vector<int>> C(H + 1, vector<int>(W + 1));
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      C[i + 1][j + 1] = C[i + 1][j] + C[i][j + 1] - C[i][j] + (S[i][j] == '#' ? 1 : 0);
    }
  }
  int ok = 1, ng = min(H, W) + 1;
  while(ng - ok > 1) {
    int m = (ok + ng) >> 1;
    vector<vector<int>> imos(H + 1, vector<int>(W + 1));
    for(int i = 0; i <= H - m; i++) {
      for(int j = 0; j <= W - m; j++) {
        if(C[i + m][j + m] - C[i][j + m] - C[i + m][j] + C[i][j] == m * m) {
          imos[i][j]++;
          imos[i][j + m]--;
          imos[i + m][j]--;
          imos[i + m][j + m]++;
        }
      }
    }
    for(int i = 0; i < H; i++) {
      for(int j = 1; j < W; j++) {
        imos[i][j] += imos[i][j - 1];
      }
    }
    for(int i = 1; i < H; i++) {
      for(int j = 0; j < W; j++) {
        imos[i][j] += imos[i - 1][j];
      }
    }
    bool fn = true;
    //cout << m << endl;
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
        //cout << imos[i][j];
        if(S[i][j] == '.' && imos[i][j] > 0) {
          fn = false;
        }
        if(S[i][j] == '#' && imos[i][j] <= 0) {
          fn = false;
        } 
      }
      //cout << endl;
    }

    if(fn) {
      ok = m;
    } else {
      ng = m;
    }
  }
  cout << ok << '\n';
  return 0;
}
0