結果

問題 No.2641 draw X
ユーザー kwm_tkwm_t
提出日時 2024-02-23 23:14:00
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 275 ms / 2,000 ms
コード長 4,637 bytes
コンパイル時間 7,606 ms
コンパイル使用メモリ 315,600 KB
実行使用メモリ 28,160 KB
最終ジャッジ日時 2024-02-23 23:14:30
合計ジャッジ時間 10,985 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 3 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 33 ms
28,160 KB
testcase_16 AC 194 ms
28,160 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 8 ms
6,676 KB
testcase_21 AC 13 ms
7,168 KB
testcase_22 AC 9 ms
6,676 KB
testcase_23 AC 10 ms
6,676 KB
testcase_24 AC 4 ms
6,676 KB
testcase_25 AC 4 ms
6,676 KB
testcase_26 AC 21 ms
7,424 KB
testcase_27 AC 6 ms
6,676 KB
testcase_28 AC 17 ms
12,416 KB
testcase_29 AC 30 ms
23,040 KB
testcase_30 AC 32 ms
19,712 KB
testcase_31 AC 29 ms
14,208 KB
testcase_32 AC 44 ms
23,040 KB
testcase_33 AC 100 ms
22,912 KB
testcase_34 AC 36 ms
14,976 KB
testcase_35 AC 39 ms
13,184 KB
testcase_36 AC 74 ms
25,472 KB
testcase_37 AC 275 ms
26,880 KB
testcase_38 AC 91 ms
24,320 KB
testcase_39 AC 107 ms
27,776 KB
testcase_40 AC 267 ms
26,496 KB
testcase_41 AC 59 ms
24,320 KB
testcase_42 AC 113 ms
25,344 KB
testcase_43 AC 105 ms
24,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint998244353;
//const int mod = 998244353;
//using mint = modint1000000007;
//const int mod = 1000000007;
const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
template <class T, class F>
T binarySearch(T ok, T ng, const F &f) {
	while (abs(ok - ng) > 1) {
		T mid = (ok + ng) / 2;
		(f(mid) ? ok : ng) = mid;
	}
	return ok;
}
template <class T>
class CrossPrefixSum {
	// 斜め累積和
public:
	CrossPrefixSum(int h, int w, const std::vector<std::vector<T>> &org) :h(h), w(w) {
		init(org);
	}
	// 0:左上->1;右下(引数は閉区間)
	T getRui0(int i0, int j0, int i1, int j1) {
		return rui0[i1 + 1][j1 + 1] - rui0[i0][j0];
	}
	// 0:右上→1;左下(引数は閉区間)
	T getRui1(int i0, int j0, int i1, int j1) {
		return rui1[i1 + 1][j1] - rui1[i0][j0 + 1];
	};
private:
	int h, w;
	std::vector<std::vector<T>>rui0;//左上→右下
	std::vector<std::vector<T>>rui1;//右上→左下
	void init(const std::vector<std::vector<T>> &org) {
		rui0.assign(h + 1, std::vector<T>(w + 1));
		rui1.assign(h + 1, std::vector<T>(w + 1));
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				rui0[i + 1][j + 1] = org[i][j];
				rui1[i + 1][j + 0] = org[i][j];
			}
		}
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				rui0[i + 1][j + 1] += rui0[i + 0][j + 0];
				rui1[i + 1][j + 0] += rui1[i + 0][j + 1];
			}
		}
	}
};
template <class T>
class CrossImos {
	// 斜めimos
public:
	CrossImos(int h, int w) :h(h), w(w) {
		init();
	}
	void init() {
		imos0.assign(h + 1, std::vector<T>(w + 1));
		imos1.assign(h + 1, std::vector<T>(w + 1));
	}
	// 0:左上->1;右下(引数は閉区間)
	void add0(int i0, int j0, int i1, int j1, T val) {
		imos0[i0 + 0][j0 + 0] += val;
		imos0[i1 + 1][j1 + 1] -= val;
	}
	// 0:右上→1;左下(引数は閉区間)
	void add1(int i0, int j0, int i1, int j1, T val) {
		imos1[i0 + 0][j0 + 1] += val;
		imos1[i1 + 1][j1 + 0] -= val;
	}
	T get0(int i, int j) {
		return imos0[i][j];
	}
	T get1(int i, int j) {
		return imos1[i][j + 1];
	}
	void build() {
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				imos0[i + 1][j + 1] += imos0[i + 0][j + 0];
				imos1[i + 1][j + 0] += imos1[i + 0][j + 1];
			}
		}
	}
	void dump() {
		for (int i = 0; i < h + 1; ++i) {
			for (int j = 0; j < w + 1; ++j) {
				std::cout << imos0[i][j] << " ";
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;
		for (int i = 0; i < h + 1; ++i) {
			for (int j = 0; j < w + 1; ++j) {
				std::cout << imos1[i][j] << " ";
			}
			std::cout << std::endl;
		}
	};
private:
	int h, w;
	std::vector<std::vector<T>>imos0;//左上→右下
	std::vector<std::vector<T>>imos1;//右上→左下
};
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int h, w; cin >> h >> w;
	vector<string>s(h);
	rep(i, h)cin >> s[i];
	vector b(h, vector<int>(w));
	rep(i, h)rep(j, w) {
		if ('#' == s[i][j])b[i][j] = 1;
	}
	// 斜め累積和
	auto crossPrefixSum = CrossPrefixSum<int>(h, w, b);
	// 斜めImos
	auto crossImos = CrossImos<int>(h, w);

	vector cnt(h, vector<int>(w));
	rep(i, h)rep(j, w) {
		if ('.' == s[i][j])continue;

		auto f = [&](long long x)->bool {
			int y = x * 2 + 1;
			{
				int i0 = i - x;
				int j0 = j - x;
				int i1 = i + x;
				int j1 = j + x;
				int cnt = crossPrefixSum.getRui0(i0, j0, i1, j1);
				if (cnt < y)return false;
			}
			{
				int i0 = i - x;
				int j0 = j + x;
				int i1 = i + x;
				int j1 = j - x;
				int cnt = crossPrefixSum.getRui1(i0, j0, i1, j1);
				if (cnt < y)return false;
			}
			return true;
		};
		int lim = min({ i,j,h - 1 - i,w - 1 - j }) + 1;
		auto get = binarySearch<int>(0, lim, f);
		if (0 == get)continue;
		crossImos.add0(i - get, j - get, i + get, j + get, 1);
		crossImos.add1(i - get, j + get, i + get, j - get, 1);
	}
	crossImos.build();
	bool chk = true;
	rep(i, h)rep(j, w) {
		if ('.' == s[i][j])continue;
		int cnt = crossImos.get0(i, j) + crossImos.get1(i, j);
		if (0 == cnt)chk = false;
	}
	cout << (chk ? "Yes" : "No") << endl;
	return 0;
}
0