結果

問題 No.2641 draw X
ユーザー AerenAeren
提出日時 2024-02-19 22:04:28
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 2,374 bytes
コンパイル時間 3,347 ms
コンパイル使用メモリ 257,120 KB
実行使用メモリ 28,032 KB
最終ジャッジ日時 2024-02-19 22:04:35
合計ジャッジ時間 5,495 ms
ジャッジサーバーID
(参考情報)
judge16 / 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 1 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 1 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 1 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 33 ms
28,032 KB
testcase_16 AC 40 ms
28,032 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 4 ms
6,676 KB
testcase_21 AC 8 ms
7,168 KB
testcase_22 AC 4 ms
6,676 KB
testcase_23 AC 6 ms
6,676 KB
testcase_24 AC 3 ms
6,676 KB
testcase_25 AC 3 ms
6,676 KB
testcase_26 AC 9 ms
7,424 KB
testcase_27 AC 3 ms
6,676 KB
testcase_28 AC 12 ms
11,904 KB
testcase_29 AC 24 ms
22,528 KB
testcase_30 AC 22 ms
19,328 KB
testcase_31 AC 18 ms
13,952 KB
testcase_32 AC 28 ms
22,656 KB
testcase_33 AC 33 ms
22,400 KB
testcase_34 AC 18 ms
14,464 KB
testcase_35 AC 16 ms
12,928 KB
testcase_36 AC 34 ms
25,472 KB
testcase_37 AC 42 ms
26,752 KB
testcase_38 AC 37 ms
24,192 KB
testcase_39 AC 42 ms
27,648 KB
testcase_40 AC 41 ms
26,368 KB
testcase_41 AC 32 ms
24,320 KB
testcase_42 AC 39 ms
25,216 KB
testcase_43 AC 39 ms
24,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
// #include <x86intrin.h>
using namespace std;
#if __cplusplus >= 202002L
using namespace numbers;
#endif
template<class T> T &ctmin(T &x){ return x; }
template<class T, class Head, class ...Tail> T &ctmin(T &x, const Head &h, const Tail &... t){ return ctmin(x = min<T>(x, h), t...); }
template<class T> T &ctmax(T &x){ return x; }
template<class T, class Head, class ...Tail> T &ctmax(T &x, const Head &h, const Tail &... t){ return ctmax(x = max<T>(x, h), t...); }



int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	int nr, nc;
	cin >> nr >> nc;
	vector<string> a(nr);
	copy_n(istream_iterator<string>(cin), nr, a.begin());
	vector ul(nr, vector(nc, 1));
	auto ur = ul;
	auto dl = ul;
	auto dr = ul;
	for(auto x = 0; x < nr; ++ x){
		for(auto y = 0; y < nc; ++ y){
			if(a[x][y] == '.'){
				ul[x][y] = ur[x][y] = 0;
				continue;
			}
			if(x >= 1){
				if(y >= 1){
					ul[x][y] = ul[x - 1][y - 1] + 1;
				}
				if(y + 1 < nc){
					ur[x][y] = ur[x - 1][y + 1] + 1;
				}
			}
		}
	}
	for(auto x = nr - 1; x >= 0; -- x){
		for(auto y = 0; y < nc; ++ y){
			if(a[x][y] == '.'){
				dl[x][y] = dr[x][y] = 0;
				continue;
			}
			if(x + 1 < nr){
				if(y >= 1){
					dl[x][y] = dl[x + 1][y - 1] + 1;
				}
				if(y + 1 < nc){
					dr[x][y] = dr[x + 1][y + 1] + 1;
				}
			}
		}
	}
	vector<vector<int>> res_sum(nr, vector<int>(nc));
	vector<vector<int>> res_dif(nr, vector<int>(nc));
	for(auto x = 1; x < nr - 1; ++ x){
		for(auto y = 1; y < nc - 1; ++ y){
			int radius = min({ul[x][y], ur[x][y], dl[x][y], dr[x][y]});
			if(radius <= 1){
				continue;
			}
			++ res_sum[x - radius + 1][y - radius + 1];
			if(x + radius < nr && y + radius < nc){
				-- res_sum[x + radius][y + radius];
			}
			++ res_dif[x - radius + 1][y + radius - 1];
			if(x + radius < nr && y - radius >= 0){
				-- res_dif[x + radius][y - radius];
			}
		}
	}
	for(auto x = 0; x < nr - 1; ++ x){
		for(auto y = 0; y < nc; ++ y){
			if(y + 1 < nc){
				res_sum[x + 1][y + 1] += res_sum[x][y];
			}
			if(y - 1 >= 0){
				res_dif[x + 1][y - 1] += res_dif[x][y];
			}
		}
	}
	for(auto x = 0; x < nr; ++ x){
		for(auto y = 0; y < nc; ++ y){
			if(!!(res_sum[x][y] + res_dif[x][y]) != (a[x][y] == '#')){
				cout << "No\n";
				return 0;
			}
		}
	}
	cout << "Yes\n";
	return 0;
}

/*

*/
0