結果

問題 No.179 塗り分け
ユーザー suzu
提出日時 2023-05-23 12:14:09
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,777 bytes
コンパイル時間 4,661 ms
コンパイル使用メモリ 107,392 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-12-23 00:55:20
合計ジャッジ時間 5,372 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 33 WA * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Linq;
using System.Collections.Generic;

namespace yukicoder
{
	enum Colors
	{
		Black,
		White,
		Red,
		Blue
	}
	
	class pg
	{
		static void Main(string[] args)
		{
			var line1 = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToArray();
			int H = line1[0];
			int W = line1[1];
		
			var defaultColors = new Colors[H,W];
			var paintColors = new Colors[H,W];
		
			int bnum = 0;//黒の数
		
			for(int ih = 0;ih < H;ih++)
			{
				var line2 = Console.ReadLine().Select(c => c.ToString()).ToArray();
				for(int iw = 0;iw < W;iw++)
				{
					if(line2[iw] == "#")
					{
						defaultColors[ih,iw] = Colors.Black;
						bnum++;
					}else
					{	
						defaultColors[ih,iw] = Colors.White;
					}
					
				}
			}	
		
			Array.Copy(defaultColors,paintColors,defaultColors.Length);
		
		
			if(bnum % 2 == 1)//黒の数が奇数だったらnoを出力
			{
				Console.WriteLine("NO");
				return;
			}
			
			for(int gapH = 0;gapH < H;gapH++)//ずれ
			{
				for(int gapW = 0;gapW < W;gapW++)//ずれ
				{
					for(int ih = 0;ih < H;ih++)//paint更新
					{
						for(int iw = 0;iw < W;iw++)//paint更新
						{
							if(paintColors[ih,iw] == Colors.Black)
							{
								paintColors[ih,iw] = Colors.Red;
								
								if(ih + gapH >= H || iw + gapW >= W || paintColors[ih + gapH,iw + gapW] != Colors.Black)//配列を逸脱するか、塗り替え先が黒でないとき失敗
								{
									goto PaintEnd;
								}
								
								paintColors[ih + gapH,iw + gapW] = Colors.Blue;
							}
						}
					}
					Console.WriteLine("YES");//最後まで塗り替えられた
					return;
					
					PaintEnd:
					Array.Copy(defaultColors,paintColors,defaultColors.Length);
				}
			}
			Console.WriteLine("NO");
		}
	}
}	
0