結果
問題 | No.2456 Stamp Art |
ユーザー |
|
提出日時 | 2023-09-01 22:49:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 391 ms / 5,000 ms |
コード長 | 1,729 bytes |
コンパイル時間 | 4,258 ms |
コンパイル使用メモリ | 254,740 KB |
最終ジャッジ日時 | 2025-02-16 17:07:27 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#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"; }