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"); } } }