結果

問題 No.2641 draw X
ユーザー kwm_tkwm_t
提出日時 2024-02-23 22:56:04
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 3,933 bytes
コンパイル時間 6,765 ms
コンパイル使用メモリ 313,068 KB
実行使用メモリ 28,160 KB
最終ジャッジ日時 2024-02-23 22:56:17
合計ジャッジ時間 11,732 ms
ジャッジサーバーID
(参考情報)
judge13 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
6,676 KB
testcase_06 AC 2 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 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 32 ms
28,160 KB
testcase_16 AC 191 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 14 ms
7,168 KB
testcase_22 AC 8 ms
6,676 KB
testcase_23 AC 11 ms
6,676 KB
testcase_24 AC 4 ms
6,676 KB
testcase_25 AC 5 ms
6,676 KB
testcase_26 AC 17 ms
7,424 KB
testcase_27 AC 6 ms
6,676 KB
testcase_28 AC 18 ms
12,416 KB
testcase_29 AC 30 ms
23,040 KB
testcase_30 AC 33 ms
19,712 KB
testcase_31 AC 30 ms
14,208 KB
testcase_32 AC 45 ms
23,040 KB
testcase_33 AC 128 ms
22,912 KB
testcase_34 AC 42 ms
14,976 KB
testcase_35 AC 51 ms
13,184 KB
testcase_36 AC 77 ms
25,472 KB
testcase_37 AC 283 ms
26,880 KB
testcase_38 AC 94 ms
24,320 KB
testcase_39 AC 102 ms
27,776 KB
testcase_40 AC 276 ms
26,496 KB
testcase_41 AC 62 ms
24,320 KB
testcase_42 AC 125 ms
25,344 KB
testcase_43 AC 112 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;
}
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;
	}
	// 斜め累積和
	vector rui0(h + 1, vector<int>(w + 1));//左上→右下
	vector rui1(h + 1, vector<int>(w + 1));//右上→左下
	rep(i, h)rep(j, w) {
		rui0[i + 1][j + 1] = b[i][j];
		rui1[i + 1][j + 0] = b[i][j];
	}
	rep(i, h)rep(j, w) {
		rui0[i + 1][j + 1] += rui0[i + 0][j + 0];
		rui1[i + 1][j + 0] += rui1[i + 0][j + 1];
	}
	// 0:左上->1;右下(引数は閉区間)
	auto cntRui0 = [&](int i0, int j0, int i1, int j1)->int {
		return rui0[i1 + 1][j1 + 1] - rui0[i0][j0];
	};
	// 0:右上→1;左下(引数は閉区間)
	auto cntRui1 = [&](int i0, int j0, int i1, int j1)->int {
		return rui1[i1 + 1][j1] - rui1[i0][j0 + 1];
	};
	// 斜めimos
	vector imos0(h + 1, vector<int>(w + 1));//左上→右下
	vector imos1(h + 1, vector<int>(w + 1));//右上→左下
	// 0:左上->1;右下(引数は閉区間)
	auto add0 = [&](int i0, int j0, int i1, int j1)->void {
		imos0[i0 + 0][j0 + 0]++;
		imos0[i1 + 1][j1 + 1]--;
	};
	// 0:右上→1;左下(引数は閉区間)
	auto add1 = [&](int i0, int j0, int i1, int j1)->void {
		imos1[i0 + 0][j0 + 1]++;
		imos1[i1 + 1][j1 + 0]--;
	};
	auto build0 = [&]()->void {
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				imos0[i + 1][j + 1] += imos0[i][j];
			}
		}
	};
	auto build1 = [&]()->void {
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				imos1[i + 1][j + 0] += imos1[i + 0][j + 1];
			}
		}
	};
	auto dump0 = [&]()->void {
		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;
		}
	};
	auto dump1 = [&]()->void {
		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;
		}
	};
	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 = cntRui0(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 = cntRui1(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);
		//cout << i << " " << j << " " << get << endl;
		if (0 == get)continue;
		add0(i - get, j - get, i + get, j + get);
		add1(i - get, j + get, i + get, j - get);
	}
	build0();
	//dump0();
	build1();
	//dump1();
	bool chk = true;
	rep(i, h)rep(j, w) {
		if ('.' == s[i][j])continue;
		int cnt = imos0[i][j] + imos1[i][j + 1];
		if (0 == cnt)chk = false;
	}
	cout << (chk ? "Yes" : "No") << endl;
	return 0;
}
0