結果

問題 No.179 塗り分け
コンテスト
ユーザー T
提出日時 2025-11-24 20:26:04
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,702 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2025-11-24 20:26:08
合計ジャッジ時間 3,895 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5 WA * 1
other AC * 25 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

H,W = map(int,input().split())
S = [input().strip() for i in range(H)]
black = []
for i in range(H):
	for j in range(W):
		if (S[i][j] == "#"):
			black.append((i,j))
		else:
			pass

if (len(black) % 2 != 0):
	print("NO")
	exit()

#黒座標を集合に変換
black_base = set(black)

# 黒マスの任意のペアを使って dx,dy を決定
for i in range(len(black)):
	x1 , y1 = black[i]
	for j in range (i+1, len(black)):
		x2 , y2 = black[j]
		dx = x2 - x1
		dy = y2 - y1
		
		A = []
		B = []
		check = True
		group = []
		count = 0
		
		if (dy > 0):
			# 各黒マスを 赤と青 に分類する
			for (p,q) in black:
				if ((p + dx , q + dy) in black_base):
					A.append((p,q))
				elif((p - dx , q - dy) in black_base):
					B.append((p,q))
				else:
					check = False
					break
			if((check == True) and (len(A) > 0) and (len(B) > 0)):
				print("YES")
				exit()
		#一列のみの時の処理
		elif (dy == 0):
			for c in S:
				if (c == "#"):
					count += 1
				else:
					if (count > 0):
						group.append(count)
						count = 0
			#最後が黒のときの処理
			if (count > 0):
				group.append(count)
			#同じ形を消込
			while True:
				remove = False
				for a in range(len(group)):
					for b in range(a+1, len(group)):
						if (group[a] == group[b]):
							group.pop(a)
							group.pop(b)
							remove = True
							break
					if (remove == True):
						break
				if (not remove == True):
					break
			#残った形で場合分け
			if (len(group) == 0):
				print("YES")
				exit()
			elif (len(group) == 1):
				if(group[0] % 2 == 0):
					print("YES")
					exit()
				else:
					print("NO")
					exit()
			else:
				print("NO")
				exit()
				
print("NO")
0