結果
| 問題 |
No.2456 Stamp Art
|
| コンテスト | |
| ユーザー |
emthrm
|
| 提出日時 | 2023-09-01 21:56:58 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 881 ms / 5,000 ms |
| コード長 | 3,061 bytes |
| コンパイル時間 | 3,101 ms |
| コンパイル使用メモリ | 256,012 KB |
| 実行使用メモリ | 38,912 KB |
| 最終ジャッジ日時 | 2024-06-11 17:57:27 |
| 合計ジャッジ時間 | 15,363 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
IOSetup() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << fixed << setprecision(20);
}
} iosetup;
template <typename T>
struct CumulativeSum2D {
explicit CumulativeSum2D(const int h, const int w)
: CumulativeSum2D(std::vector<std::vector<T>>(h, std::vector<T>(w, 0))) {}
template <typename U>
explicit CumulativeSum2D(const std::vector<std::vector<U>>& a)
: is_built(false), h(a.size()), w(a.front().size()),
data(h + 1, std::vector<T>(w + 1, 0)) {
for (int i = 0; i < h; ++i) {
std::copy(a[i].begin(), a[i].end(), std::next(data[i + 1].begin()));
}
}
void add(const int y, const int x, const T val) {
assert(!is_built);
data[y + 1][x + 1] += val;
}
void build() {
assert(!is_built);
is_built = true;
for (int i = 0; i < h; ++i) {
std::partial_sum(data[i + 1].begin(), data[i + 1].end(),
data[i + 1].begin());
}
for (int j = 1; j <= w; ++j) {
for (int i = 1; i < h; ++i) {
data[i + 1][j] += data[i][j];
}
}
}
T query(const int y1, const int x1, const int y2, const int x2) const {
assert(is_built);
return y1 > y2 || x1 > x2 ? 0 : data[y2 + 1][x2 + 1] - data[y2 + 1][x1]
- data[y1][x2 + 1] + data[y1][x1];
}
private:
bool is_built;
const int h, w;
std::vector<std::vector<T>> data;
};
int main() {
int h, w; cin >> h >> w;
vector<string> s(h); REP(i, h) cin >> s[i];
CumulativeSum2D<int> cs(h, w);
REP(i, h) REP(j, w) {
if (s[i][j] == '#') cs.add(i, j, 1);
}
cs.build();
int lb = 1, ub = min(h, w) + 1;
while (ub - lb > 1) {
const int k = midpoint(lb, ub);
vector grid(h, vector(w, 0));
REP(i, h - k + 1) REP(j, w - k + 1) {
if (cs.query(i, j, i + k - 1, j + k - 1) == k * k) {
++grid[i][j];
if (i + k < h) --grid[i + k][j];
if (j + k < w) --grid[i][j + k];
if (i + k < h && j + k < w) ++grid[i + k][j + k];
}
}
REP(i, h) FOR(j, 1, w) grid[i][j] += grid[i][j - 1];
REP(j, w) FOR(i, 1, h) grid[i][j] += grid[i - 1][j];
bool is_valid = true;
REP(i, h) REP(j, w) {
if (s[i][j] == '#' && grid[i][j] == 0) {
is_valid = false;
break;
}
}
(is_valid ? lb : ub) = k;
}
cout << lb << '\n';
return 0;
}
emthrm