結果

問題 No.2641 draw X
ユーザー maeshunmaeshun
提出日時 2024-02-20 10:56:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,974 ms / 2,000 ms
コード長 2,366 bytes
コンパイル時間 4,733 ms
コンパイル使用メモリ 281,344 KB
実行使用メモリ 91,628 KB
最終ジャッジ日時 2024-02-20 10:56:29
合計ジャッジ時間 17,664 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 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 1 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 1 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 81 ms
35,968 KB
testcase_16 AC 1,305 ms
91,628 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 53 ms
7,380 KB
testcase_21 AC 59 ms
8,960 KB
testcase_22 AC 84 ms
9,652 KB
testcase_23 AC 36 ms
7,680 KB
testcase_24 AC 6 ms
6,676 KB
testcase_25 AC 8 ms
6,676 KB
testcase_26 AC 112 ms
12,052 KB
testcase_27 AC 52 ms
6,676 KB
testcase_28 AC 62 ms
16,000 KB
testcase_29 AC 74 ms
28,288 KB
testcase_30 AC 98 ms
23,680 KB
testcase_31 AC 130 ms
19,456 KB
testcase_32 AC 187 ms
28,288 KB
testcase_33 AC 1,162 ms
88,788 KB
testcase_34 AC 496 ms
50,196 KB
testcase_35 AC 518 ms
46,288 KB
testcase_36 AC 334 ms
35,184 KB
testcase_37 AC 1,969 ms
91,428 KB
testcase_38 AC 486 ms
35,428 KB
testcase_39 AC 499 ms
40,928 KB
testcase_40 AC 1,974 ms
90,844 KB
testcase_41 AC 249 ms
30,208 KB
testcase_42 AC 670 ms
44,760 KB
testcase_43 AC 626 ms
43,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for(int i=0;i<(n);++i)
#define rep1(i, n) for(int i=1;i<=(n);i++)
#define ll long long
using mint = modint998244353;
using P = pair<ll,ll>;
using lb = long double;
using T = tuple<ll, ll, ll>;
#ifdef LOCAL
#  include <debug_print.hpp>
#  define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define dbg(...) (static_cast<void>(0))
#endif

int main()
{
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i,h) cin >> s[i];
	vector<vector<int>> a(h+w+5), b(h+w+5);
	rep(i,h)rep(j,w){
		if(s[i][j]=='.') {
			a[i+j+2].push_back(j);
			b[i-j+w+2].push_back(j);
		}
	}
	for(int i=-1;i<=h;i++){
		for(int j=-1;j<=w;j++){
			if(i<0 || i>=h || j<0 || j>=w) {
				a[i+j+2].push_back(j);
				b[i-j+w+2].push_back(j);
			}
		}
	}
	for(auto &p : a){
		sort(p.begin(),p.end());
		p.erase(unique(p.begin(),p.end()), p.end());
	}

	for(auto &p : b){
		sort(p.begin(),p.end());
		p.erase(unique(p.begin(),p.end()), p.end());
	}
	dbg(a,b);
	vector<vector<vector<int>>> dp(4, vector<vector<int>>(h, vector<int>(w)));
	rep(i,h)rep(j,w){
		if(s[i][j]=='#'){
			int p = lower_bound(a[i+j+2].begin(),a[i+j+2].end(), j) - a[i+j+2].begin();
			int q = p-1;
			int r = lower_bound(b[i-j+w+2].begin(),b[i-j+w+2].end(), j) - b[i-j+w+2].begin();
			int s = r-1;
			int d = min(a[i+j+2][p]-j, j-a[i+j+2][q]);
			d = min(d, b[i-j+w+2][r]-j);
			d = min(d, j-b[i-j+w+2][s]);
			if(d==1) continue;
			dbg(d);
			rep(k,4) dp[k][i][j] = max(dp[k][i][j], d);
			dbg(i,j,d);
		}
	}
	using R = tuple<int, int, int, int>;
	priority_queue<R> pq;
	rep(i,h)rep(j,w){
		if(s[i][j]=='.' || dp[0][i][j]==0) continue;
		rep(k,4) pq.emplace(dp[k][i][j], i,j,k);
	}
	vector<int> di = {-1,-1,1,1};
	vector<int> dj = {-1,1,-1,1};
	while(!pq.empty()){
		auto [d, x, y, k] = pq.top();pq.pop();
		if(dp[k][x][y]!=d) continue;
		int nx = x + di[k];
		int ny = y + dj[k];
		if(nx<0 || ny<0 || nx>=h || ny>=w) continue;
		if(s[nx][ny]=='.') continue;
		if(dp[k][nx][ny]<d-1) {
			dp[k][nx][ny] = d-1;
			if(dp[k][nx][ny]==1) continue;
			pq.emplace(d-1, nx, ny, k);
		}
	}
	dbg(dp);
	rep(i,h)rep(j,w){
		if(s[i][j]=='#'){
			int d = 0;
			rep(k,4){
				d = max(d, dp[k][i][j]);
			}
			if(d==0){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}
0