結果

問題 No.2641 draw X
ユーザー maeshunmaeshun
提出日時 2024-02-20 10:54:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,285 bytes
コンパイル時間 4,680 ms
コンパイル使用メモリ 281,344 KB
実行使用メモリ 102,084 KB
最終ジャッジ日時 2024-02-20 10:55:10
合計ジャッジ時間 31,103 ms
ジャッジサーバーID
(参考情報)
judge14 / 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 1 ms
6,676 KB
testcase_07 AC 10 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 1,074 ms
102,084 KB
testcase_16 AC 1,408 ms
91,500 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 1 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 120 ms
9,688 KB
testcase_21 AC 225 ms
24,392 KB
testcase_22 AC 115 ms
9,524 KB
testcase_23 AC 171 ms
15,724 KB
testcase_24 AC 58 ms
9,948 KB
testcase_25 AC 53 ms
9,448 KB
testcase_26 AC 267 ms
24,256 KB
testcase_27 AC 65 ms
8,924 KB
testcase_28 AC 467 ms
49,564 KB
testcase_29 AC 912 ms
95,140 KB
testcase_30 AC 827 ms
90,360 KB
testcase_31 AC 671 ms
50,344 KB
testcase_32 AC 1,098 ms
95,116 KB
testcase_33 AC 1,452 ms
88,660 KB
testcase_34 AC 783 ms
50,068 KB
testcase_35 AC 798 ms
46,160 KB
testcase_36 AC 1,395 ms
96,540 KB
testcase_37 TLE -
testcase_38 AC 1,525 ms
92,656 KB
testcase_39 AC 1,683 ms
98,156 KB
testcase_40 TLE -
testcase_41 AC 1,227 ms
95,000 KB
testcase_42 AC 1,768 ms
93,792 KB
testcase_43 AC 1,690 ms
92,496 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){
		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