#abc241c. C - Connect 6

C - Connect 6

Score : 300300 points

问题描述

存在一个包含 NN 行横向和 NN 列纵向的网格,其中每个方格被涂成白色或黑色。

网格的状态由 NN 个字符串 SiS_i 表示。如果 SiS_i 的第 jj 个字符是 #,则从上到下第 ii 行、从左到右第 jj 列的方格被涂成黑色。如果字符是 ., 则该方格被涂成白色。

高桥最多可以选择两个白色方格,并将其涂成黑色。
判断是否存在一种可能性,使得网格中包含连续对齐(纵向、横向或对角线方向)的 66 个或更多黑色方格。

这里,当网格完全包含一个具有 66 行和 66 列的子网格,且该子网格至少在一个对角线上所有方格都被涂成黑色时,我们称网格包含 66 个或更多连续对齐的黑色方格(对角线方向)。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There is a grid with NN horizontal rows and NN vertical columns, where each square is painted white or black.
The state of the grid is represented by NN strings, SiS_i. If the jj-th character of SiS_i is #, the square at the ii-th row from the top and the jj-th column from the left is painted black. If the character is ., then the square is painted white.

Takahashi can choose at most two of these squares that are painted white, and paint them black.
Determine if it is possible to make the grid contain 66 or more consecutive squares painted black aligned either vertically, horizontally, or diagonally.
Here, the grid is said to be containing 66 or more consecutive squares painted black aligned diagonally if the grid with NN rows and NN columns completely contains a subgrid with 66 rows and 66 columns such that all the squares on at least one of its diagonals are painted black.

Constraints

  • 6N10006 \leq N \leq 1000
  • Si=N\lvert S_i\rvert =N
  • SiS_i consists of # and ..

Input

Input is given from Standard Input in the following format:

NN

S1S_1

S2S_2

\vdots

SNS_N

Output

If it is possible to fulfill the condition by painting at most two squares, then print Yes; otherwise, print No.

Sample Input 1

8
........
........
.#.##.#.
........
........
........
........
........

Sample Output 1

Yes

By painting the 33-rd and the 66-th squares from the left in the 33-rd row from the top, there will be 66 squares painted black aligned horizontally.

Sample Input 2

6
######
######
######
######
######
######

Sample Output 2

Yes

While Takahashi cannot choose a square to paint black, the grid already satisfies the condition.

Sample Input 3

10
..........
#..##.....
..........
..........
....#.....
....#.....
.#...#..#.
..........
..........
..........

Sample Output 3

No

update @ 2024/3/10 10:23:13