#abc302b. B - Find snuke
B - Find snuke
Score : points
问题描述
存在一个具有 行(水平方向)和 列(垂直方向)的网格。每个单元格上都写有一个小写英文字母,我们用 表示从上到下的第 行、从左到右的第 列的单元格。
网格上书写的字母由 个字符串 表示,每个字符串长度为 。其中, 的第 个字母表示在 单元格上书写的字母。
网格中存在一组唯一的连续单元格(纵向、横向或对角线方向),按照顺序依次写着 s
, n
, u
, k
, 和 e
。请找出这些单元格的位置,并按照输出部分指定的格式打印它们。
如果一个包含五个单元格的元组 满足以下所有条件,则称其形成了一组按顺序写着 s
, n
, u
, k
, 和 e
的连续单元格(纵向、横向或对角线方向):
- 和 上分别写着字母
s
,n
,u
,k
, 和e
。 - 对于所有 ,单元格 和 共享一个角或一条边。
- 和 的中心点位于同一直线上并且以等间距排列。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a grid with horizontal rows and vertical columns. Each cell has a lowercase English letter written on it. We denote by the cell at the -th row from the top and -th column from the left.
The letters written on the grid are represented by strings , each of length . The -th letter of represents the letter written on .
There is a unique set of contiguous cells (going vertically, horizontally, or diagonally) in the grid with s
, n
, u
, k
, and e
written on them in this order.
Find the positions of such cells and print them in the format specified in the Output section.
A tuple of five cells is said to form a set of contiguous cells (going vertically, horizontally, or diagonally) with s
, n
, u
, k
, and e
written on them in this order if and only if all of the following conditions are satisfied.
- and have letters
s
,n
,u
,k
, ande
written on them, respectively. - For all , cells and share a corner or a side.
- The centers of , and are on a common line at regular intervals.
Constraints
- and are integers.
- is a string of length consisting of lowercase English letters.
- The given grid has a unique conforming set of cells.
Input
The input is given from Standard Input in the following format:
Output
Print five lines in the following format.
Let be the cells in the sought set with s
, n
, u
, k
, and e
written on them, respectively. The -th line should contain and in this order, separated by a space.
In other words, print them in the following format:
See also Sample Inputs and Outputs below.
Sample Input 1
6 6
vgxgpu
amkxks
zhkbpp
hykink
esnuke
zplvfj
Sample Output 1
5 2
5 3
5 4
5 5
5 6
Tuple $(A_1,A_2,A_3,A_4,A_5)=((5,2),(5,3),(5,4),(5,5),(5,6))$ satisfies the conditions.
Indeed, the letters written on them are s
, n
, u
, k
, and e
;
for all , cells and share a side;
and the centers of the cells are on a common line.
Sample Input 2
5 5
ezzzz
zkzzz
ezuzs
zzznz
zzzzs
Sample Output 2
5 5
4 4
3 3
2 2
1 1
Tuple $(A_1,A_2,A_3,A_4,A_5)=((5,5),(4,4),(3,3),(2,2),(1,1))$ satisfies the conditions.
However, for example, $(A_1,A_2,A_3,A_4,A_5)=((3,5),(4,4),(3,3),(2,2),(3,1))$ violates the third condition because the centers of the cells are not on a common line, although it satisfies the first and second conditions.
Sample Input 3
10 10
kseeusenuk
usesenesnn
kskekeeses
nesnusnkkn
snenuuenke
kukknkeuss
neunnennue
sknuessuku
nksneekknk
neeeuknenk
Sample Output 3
9 3
8 3
7 3
6 3
5 3
update @ 2024/3/10 08:29:08