結果

問題 No.179 塗り分け
ユーザー suzusuzu
提出日時 2023-05-23 12:36:17
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 112 ms / 3,000 ms
コード長 1,865 bytes
コンパイル時間 4,468 ms
コンパイル使用メモリ 104,952 KB
実行使用メモリ 24,048 KB
最終ジャッジ日時 2023-08-24 16:57:03
合計ジャッジ時間 9,758 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
21,740 KB
testcase_01 AC 62 ms
21,804 KB
testcase_02 AC 62 ms
21,728 KB
testcase_03 AC 62 ms
23,776 KB
testcase_04 AC 61 ms
21,788 KB
testcase_05 AC 62 ms
21,892 KB
testcase_06 AC 62 ms
21,880 KB
testcase_07 AC 62 ms
19,736 KB
testcase_08 AC 73 ms
21,884 KB
testcase_09 AC 76 ms
23,828 KB
testcase_10 AC 69 ms
21,772 KB
testcase_11 AC 68 ms
24,048 KB
testcase_12 AC 74 ms
21,824 KB
testcase_13 AC 62 ms
21,768 KB
testcase_14 AC 62 ms
21,828 KB
testcase_15 AC 62 ms
21,852 KB
testcase_16 AC 62 ms
21,784 KB
testcase_17 AC 62 ms
21,808 KB
testcase_18 AC 68 ms
21,732 KB
testcase_19 AC 67 ms
21,772 KB
testcase_20 AC 64 ms
21,720 KB
testcase_21 AC 64 ms
21,824 KB
testcase_22 AC 112 ms
21,784 KB
testcase_23 AC 68 ms
22,012 KB
testcase_24 AC 76 ms
23,856 KB
testcase_25 AC 69 ms
21,820 KB
testcase_26 AC 71 ms
23,912 KB
testcase_27 AC 74 ms
23,696 KB
testcase_28 AC 69 ms
23,832 KB
testcase_29 AC 73 ms
23,884 KB
testcase_30 AC 69 ms
21,732 KB
testcase_31 AC 74 ms
21,764 KB
testcase_32 AC 70 ms
21,884 KB
testcase_33 AC 74 ms
21,868 KB
testcase_34 AC 69 ms
23,836 KB
testcase_35 AC 74 ms
21,828 KB
testcase_36 AC 62 ms
19,832 KB
testcase_37 AC 62 ms
23,880 KB
testcase_38 AC 62 ms
23,856 KB
testcase_39 AC 62 ms
23,740 KB
testcase_40 AC 62 ms
23,836 KB
testcase_41 AC 62 ms
21,720 KB
testcase_42 AC 62 ms
21,804 KB
testcase_43 AC 63 ms
23,924 KB
testcase_44 AC 64 ms
21,872 KB
testcase_45 AC 63 ms
19,788 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 || bnum == 0)//黒の数が奇数か0だったらnoを出力
			{
				Console.WriteLine("NO");
				return;
			}
			
			for(int gapH = 1 - H;gapH < H;gapH++)//ずれ
			{
				for(int gapW = 1 - W;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;
								
								int nextH = ih + gapH;
								int nextW = iw + gapW;
								if(nextH >= H || nextW >= W || nextH < 0 || nextW < 0 ||paintColors[nextH,nextW] != Colors.Black)//配列を逸脱するか、塗り替え先が黒でないとき失敗
								{
									goto PaintEnd;
								}
								
								paintColors[nextH,nextW] = Colors.Blue;
							}
						}
					}
					Console.WriteLine("YES");//最後まで塗り替えられた
					return;
					
					PaintEnd:
					Array.Copy(defaultColors,paintColors,defaultColors.Length);
				}
			}
			Console.WriteLine("NO");
		}
	}
}	
0