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