Logo
(追記) (追記ここまで)

30928번 - Yokohama Phenomena 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 1024 MB12011110892.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.

  • It is a series of eight squares in the given grid of squares.
  • Every square in the series, except for the first one, shares an edge with (is edge-adjacent to) its directly preceding square in the series.
  • The letters marked in the eight squares of the series are 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.

제한

예제 입력 1

2 4
YOHA
OKAM

예제 출력 1

8

예제 입력 2

3 4
YOKH
OKHA
KHAM

예제 출력 2

0

예제 입력 3

3 6
MAYOHA
AHOKAM
MAYOHA

예제 출력 3

80

힌트

출처

ICPC > Regionals > Asia Pacific > Japan > ICPC 2023 Asia Yokohama Regional A번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /