| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 (추가 시간 없음) | 1024 MB | 120 | 111 | 108 | 92.308% |
Do you know about Yokohama Phenomena? The phenomenon takes place when three programmers, sitting around a table, hold a single pen together above a board. A grid of squares is drawn on the board, with each square marked with a single letter. Although none of the participants purposely moves the pen, its nib, as if it has a will, goes down to one of the squares marked with Y, and then starts moving on the board. The squares passed are marked with O, K, O, H, A, and M in this order, and then the nib stops on the square marked with A.
Let us call the series of squares along such a trajectory of the nib a YOKOHAMA trace. A YOKOHAMA trace is defined as follows.
Y, O, K, O, H, A, M, and A, in this order.Note that the same square may appear more than once in the series.
Figure A.1 (a) is an illustration of the board corresponding to Sample Input 1. Figures A.1 (b) and (c) show trajectories on two of the YOKOHAMA traces. Both traces start at the leftmost square in the upper row. The same square marked with O appears twice in the trace illustrated in Figure A.1 (c).
Figure A.1. A board and trajectories on two of the YOKOHAMA traces
You are given a grid of squares, each marked with one of six letters, A, H, K, M, O, or Y. Your task is to count how many distinct YOKOHAMA traces are possible on it.
The input consists of a single test case of the following format.
$n$ $m$
$x_{1,1}$ $\cdots$ $x_{1,m}$
$\vdots$
$x_{n,1}$ $\cdots$ $x_{n,m}$
The first two integers $n$ and $m$ (1ドル ≤ n ≤ 10,ドル 1ドル ≤ m ≤ 10$) describe the size of the grid. The grid has squares arranged in an $n \times m$ matrix. The following $n$ lines describe the letters marked in the squares. The square at the $i$-th row and the $j$-th column in the grid (1ドル ≤ i ≤ n,ドル 1ドル ≤ j ≤ m$) has letter $x_{i,j}$ marked in it. Each $x_{i,j}$ is one of the six letters, A, H, K, M, O, or Y.
Output a line containing the number of distinct YOKOHAMA traces.
2 4 YOHA OKAM
8
3 4 YOKH OKHA KHAM
0
3 6 MAYOHA AHOKAM MAYOHA
80
ICPC > Regionals > Asia Pacific > Japan > ICPC 2023 Asia Yokohama Regional A번