結果

問題 No.2641 draw X
ユーザー ゆにぽけゆにぽけ
提出日時 2024-02-19 22:04:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 2,705 bytes
コンパイル時間 1,310 ms
コンパイル使用メモリ 139,456 KB
実行使用メモリ 21,248 KB
最終ジャッジ日時 2024-02-19 22:04:56
合計ジャッジ時間 3,886 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 1 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 22 ms
21,248 KB
testcase_16 AC 85 ms
21,248 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 7 ms
6,676 KB
testcase_21 AC 10 ms
6,676 KB
testcase_22 AC 8 ms
6,676 KB
testcase_23 AC 7 ms
6,676 KB
testcase_24 AC 3 ms
6,676 KB
testcase_25 AC 3 ms
6,676 KB
testcase_26 AC 13 ms
6,676 KB
testcase_27 AC 5 ms
6,676 KB
testcase_28 AC 14 ms
9,600 KB
testcase_29 AC 18 ms
17,408 KB
testcase_30 AC 22 ms
15,104 KB
testcase_31 AC 21 ms
11,136 KB
testcase_32 AC 30 ms
17,408 KB
testcase_33 AC 56 ms
17,280 KB
testcase_34 AC 26 ms
11,392 KB
testcase_35 AC 33 ms
10,368 KB
testcase_36 AC 55 ms
19,328 KB
testcase_37 AC 199 ms
20,352 KB
testcase_38 AC 67 ms
18,560 KB
testcase_39 AC 71 ms
20,992 KB
testcase_40 AC 174 ms
20,096 KB
testcase_41 AC 43 ms
18,560 KB
testcase_42 AC 84 ms
19,200 KB
testcase_43 AC 79 ms
18,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <random>
#include <utility>
#include <functional>
using namespace std;
void Main()
{
	int H,W;
	cin >> H >> W;
	vector<string> S(H);
	vector<vector<int>> A(H,vector<int>(W)),B(H,vector<int>(W));
	for(int i = 0;i < H;i++)
	{
		cin >> S[i];
		for(int j = 0;j < W;j++)
		{
			if(S[i][j] == '#')
			{
				A[i][j]++;
				B[i][j]++;
			}
		}
	}
	for(int i = 0;i < H;i++)
	{
		for(int j = 0;j < W;j++)
		{
			if(i - 1 >= 0 && j - 1 >= 0)
			{
				A[i][j] += A[i - 1][j - 1];
			}
			if(i - 1 >= 0 && j + 1 < W)
			{
				B[i][j] += B[i - 1][j + 1];
			}
		}
	}
	vector<vector<int>> C(H,vector<int>(W,0)),D(H,vector<int>(W,0));
	for(int i = 0;i < H;i++)
	{
		for(int j = 0;j < W;j++)
		{
			if(S[i][j] == '.')
			{
				continue;
			}
			int ok = 0,ng = min(H,W) + 1;
			while(ng - ok > 1)
			{
				int mid = (ok + ng) / 2;
				if(i + mid >= H)
				{
					ng = mid;
					continue;
				}
				if(i - mid < 0)
				{
					ng = mid;
					continue;
				}
				if(j + mid >= W)
				{
					ng = mid;
					continue;
				}
				if(j - mid < 0)
				{
					ng = mid;
					continue;
				}
				bool check = true;
				{
					int S = 0;
					S += A[i + mid][j + mid];
					if(i - mid - 1 >= 0 && j - mid - 1 >= 0)
					{
						S -= A[i - mid - 1][j - mid - 1];
					}
					check &= (S == 2 * mid + 1);
				}
				{
					int S = 0;
					S += B[i + mid][j - mid];
					if(i - mid - 1 >= 0 && j + mid + 1 < W)
					{
						S -= B[i - mid - 1][j + mid + 1];
					}
					check &= (S == 2 * mid + 1);
				}
				if(check)
				{
					ok = mid;
				}
				else
				{
					ng = mid;
				}
			}
			int mx = ok;
			if(mx == 0)
			{
				continue;
			}
			C[i + mx][j + mx]++;
			if(i - mx - 1 >= 0 && j - mx - 1 >= 0)
			{
				C[i - mx - 1][j - mx - 1]--;
			}
			D[i + mx][j - mx]++;
			if(i - mx - 1 >= 0 && j + mx + 1 < W)
			{
				D[i - mx - 1][j + mx + 1]--;
			}
		}
	}
	vector<string> T(H,string(W,'.'));
	for(int i = H - 1;i >= 0;i--)
	{
		for(int j = W - 1;j >= 0;j--)
		{
			if(i - 1 >= 0 && j - 1 >= 0)
			{
				C[i - 1][j - 1] += C[i][j];
			}
			if(i - 1 >= 0 && j + 1 < W)
			{
				D[i - 1][j + 1] += D[i][j];
			}
			if(C[i][j] || D[i][j])
			{
				T[i][j] = '#';
			}
		}
	}
	cout << (S == T ? "Yes\n":"No\n");
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	/* cin >> tt; */
	while(tt--) Main();
}

0