結果

問題 No.2641 draw X
ユーザー maeshunmaeshun
提出日時 2024-02-20 10:38:04
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,249 bytes
コンパイル時間 5,355 ms
コンパイル使用メモリ 289,492 KB
実行使用メモリ 124,060 KB
最終ジャッジ日時 2024-09-29 03:26:59
合計ジャッジ時間 27,833 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30 WA * 2 TLE * 3 -- * 6
権限があれば一括ダウンロードができます

ソースコード

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];
	map<int, vector<int>> a, b;
	rep(i,h)rep(j,w){
		a[i+j].push_back(-1);
		a[i+j].push_back(w);
		b[i-j].push_back(-1);
		b[i-j].push_back(w);
		if(s[i][j]=='.') {
			a[i+j].push_back(j);
			b[i-j].push_back(j);
		}
	}
	for(auto &p : a){
		sort(p.second.begin(),p.second.end());
		p.second.erase(unique(p.second.begin(),p.second.end()), p.second.end());
	}

	for(auto &p : b){
		sort(p.second.begin(),p.second.end());
		p.second.erase(unique(p.second.begin(),p.second.end()), p.second.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].begin(),a[i+j].end(), j) - a[i+j].begin();
			int q = p-1;
			int r = lower_bound(b[i-j].begin(),b[i-j].end(), j) - b[i-j].begin();
			int s = r-1;
			int d = min(a[i+j][p]-j, j-a[i+j][q]);
			d = min(d, b[i-j][r]-j);
			d = min(d, j-b[i-j][s]);
			if(d==1) continue;
			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){
		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;
			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