結果

問題 No.2456 Stamp Art
ユーザー KumaTachiRenKumaTachiRen
提出日時 2023-09-01 22:49:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 370 ms / 5,000 ms
コード長 1,729 bytes
コンパイル時間 4,197 ms
コンパイル使用メモリ 263,464 KB
実行使用メモリ 38,996 KB
最終ジャッジ日時 2023-09-02 11:19:15
合計ジャッジ時間 10,538 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 261 ms
38,932 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 304 ms
38,996 KB
testcase_07 AC 328 ms
38,936 KB
testcase_08 AC 295 ms
38,928 KB
testcase_09 AC 338 ms
38,984 KB
testcase_10 AC 354 ms
38,964 KB
testcase_11 AC 286 ms
38,940 KB
testcase_12 AC 319 ms
38,992 KB
testcase_13 AC 368 ms
38,940 KB
testcase_14 AC 370 ms
38,904 KB
testcase_15 AC 255 ms
38,924 KB
testcase_16 AC 125 ms
21,052 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 165 ms
26,972 KB
testcase_20 AC 329 ms
38,940 KB
testcase_21 AC 317 ms
35,736 KB
testcase_22 AC 343 ms
38,916 KB
testcase_23 AC 11 ms
5,280 KB
testcase_24 AC 24 ms
6,520 KB
testcase_25 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

struct Fast {
  Fast() {
    std::cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(10);
  }
} fast;

#define all(a) (a).begin(), (a).end()
#define contains(a, x) ((a).find(x) != (a).end())
#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--)
#define writejoin(s, a) rep(_i, 0, (a).size()) cout << (a)[_i] << (_i + 1 < (int)(a).size() ? s : "\n");
#define YN(b) cout << ((b) ? "YES" : "NO") << "\n";
#define Yn(b) cout << ((b) ? "Yes" : "No") << "\n";
#define yn(b) cout << ((b) ? "yes" : "no") << "\n";

using ll = long long;
using mint = modint998244353;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, 0, h) cin >> s[i];

  vector<vector<int>> sum(h + 1, vector<int>(w + 1, 0));
  rep(i, 0, h) rep(j, 0, w) sum[i + 1][j + 1] = s[i][j] == '#';
  rep(i, 0, h) rep(j, 0, w + 1) sum[i + 1][j] += sum[i][j];
  rep(i, 0, h + 1) rep(j, 0, w) sum[i][j + 1] += sum[i][j];

  int l = 1, r = min(h, w) + 1;
  while (r - l > 1) {
    int m = l + (r - l) / 2;
    vector<vector<int>> a(h + 1, vector<int>(w + 1, 0));
    rep(i, 0, h - m + 1) rep(j, 0, w - m + 1) {
      if (sum[i + m][j + m] + sum[i][j] - sum[i + m][j] - sum[i][j + m] == m * m) {
        a[i][j]++;
        a[i + m][j + m]++;
        a[i + m][j]--;
        a[i][j + m]--;
      }
    }
    rep(i, 0, h) rep(j, 0, w) a[i + 1][j] += a[i][j];
    rep(i, 0, h) rep(j, 0, w) a[i][j + 1] += a[i][j];
    bool ok = true;
    rep(i, 0, h) rep(j, 0, w) ok &= s[i][j] == '.' || a[i][j] > 0;
    if (ok)
      l = m;
    else
      r = m;
  }
  cout << l << "\n";
}
0