#abc312b. B - TaK Code

B - TaK Code

Score : 200200 points

问题描述

高桥发明了一种二维码——Takahashi 码(简称 TaK Code)。一个 TaK Code 满足以下所有条件:

  • 它由九行横排和九列竖排构成的区域。
  • 左上角和右下角的三行三列区域内共 1818 个单元格都是黑色的。
  • 与左上角或右下角三行三列区域相邻(水平、垂直或对角线方向)的全部 1414 个单元格为白色。

不允许旋转 TaK Code。

现在给定一个包含 NN 行和 MM 列的网格。网格的状态通过 NN 个长度为 MM 的字符串 S1,,SNS_1,\ldots,S_N 描述,其中第 ii 行从上到下、第 jj 列从左到右的单元格如果在 SiS_i 中的第 jj 个字符是 #,则表示该单元格为黑色;如果是.,则表示为白色。

找出网格内所有满足 TaK Code 条件的九行九列完全包含在内的区域。

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

Problem Statement

Takahashi invented Tak Code, a two-dimensional code. A TaK Code satisfies all of the following conditions:

  • It is a region consisting of nine horizontal rows and nine vertical columns.
  • All the 1818 cells in the top-left and bottom-right three-by-three regions are black.
  • All the 1414 cells that are adjacent (horizontally, vertically, or diagonally) to the top-left or bottom-right three-by-three region are white.

It is not allowed to rotate a TaK Code.

You are given a grid with NN horizontal rows and MM vertical columns. The state of the grid is described by NN strings, S1,S_1,\ldots, and SNS_N, each of length MM. The cell at the ii-th row from the top and jj-th column from the left is black if the jj-th character of SiS_i is #, and white if it is ..

Find all the nine-by-nine regions, completely contained in the grid, that satisfy the conditions of a TaK Code.

Constraints

  • 9N,M1009 \leq N,M \leq 100
  • NN and MM are integers.
  • SiS_i is a string of length MM consisting of . and #.

Input

The input is given from Standard Input in the following format:

NN MM

S1S_1

\vdots

SNS_N

Output

For all pairs (i,j)(i,j) such that the nine-by-nine region, whose top-left cell is at the ii-th row from the top and jj-th columns from the left, satisfies the conditions of a TaK Code, print a line containing ii, a space, and jj in this order.
The pairs must be sorted in lexicographical ascending order; that is, ii must be in ascending order, and within the same ii, jj must be in ascending order.

Sample Input 1

19 18
###......###......
###......###......
###..#...###..#...
..............#...
..................
..................
......###......###
......###......###
......###......###
.###..............
.###......##......
.###..............
............###...
...##.......###...
...##.......###...
.......###........
.......###........
.......###........
........#.........

Sample Output 1

1 1
1 10
7 7
10 2

A TaK Code looks like the following, where # is a black cell, . is a white cell, and ? can be either black or white.

###.?????
###.?????
###.?????
....?????
?????????
?????....
?????.###
?????.###
?????.###

In the grid given by the input, the nine-by-nine region, whose top-left cell is at the 1010-th row from the top and 22-nd column from the left, satisfies the conditions of a TaK Code, as shown below.

###......
###......
###......
.........
..##.....
..##.....
......###
......###
......###

Sample Input 2

9 21
###.#...........#.###
###.#...........#.###
###.#...........#.###
....#...........#....
#########...#########
....#...........#....
....#.###...###.#....
....#.###...###.#....
....#.###...###.#....

Sample Output 2

1 1

Sample Input 3

18 18
######............
######............
######............
######............
######............
######............
..................
..................
..................
..................
..................
..................
............######
............######
............######
............######
............######
............######

Sample Output 3

There may be no region that satisfies the conditions of TaK Code.

update @ 2024/3/10 08:53:05