結果

問題 No.2456 Stamp Art
ユーザー KudeKude
提出日時 2023-09-01 22:26:13
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 169 ms / 5,000 ms
コード長 1,658 bytes
コンパイル時間 2,873 ms
コンパイル使用メモリ 274,544 KB
実行使用メモリ 38,932 KB
最終ジャッジ日時 2024-06-11 17:58:59
合計ジャッジ時間 6,435 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

int dp1[2010][2010];
int dp2[2010][2010];

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  for(int i = 1; i <= h; i++) {
    for(int j = 1; j <= w; j++) {
      if (s[i-1][j-1] == '.') continue;
      dp1[i][j] = min({dp1[i-1][j], dp1[i][j-1], dp1[i-1][j-1]}) + 1;
    }
  }
  int l = 0, r = 2010;
  while(r - l > 1) {
    int c = (l + r) / 2;
    rep(i, h + 1) rep(j, w + 1) dp2[i][j] = 0;
    rep(i, h + 1) rep(j, w + 1) if (dp1[i][j] >= c) {
      dp2[i-c][j-c]++;
      dp2[i-c][j]--;
      dp2[i][j-c]--;
      dp2[i][j]++;
    }
    rep(i, h) rep(j, w) dp2[i+1][j] += dp2[i][j];
    rep(i, h) rep(j, w) dp2[i][j+1] += dp2[i][j];
    bool ok = [&]() -> bool {
      rep(i, h) rep(j, w) if (s[i][j] == '#' && !dp2[i][j]) {
        return false;
      }
      return true;
    }();
    (ok ? l : r) = c;
  }
  cout << l << '\n';
}
0