PivotOJ

Linguistic Labyrinth

시간 제한: 15000ms메모리 제한: 2048MB출처: BAPC 2025BOJ 35215

문제

It is the 25th of December, 2025. As a Christmas tradition, you gather a group of friends to solve a puzzle. Among your friends are wordcels and shape rotators, who are respectively better at thinking with words and with mental images. This puzzle challenges even the smartest wordcel and the most brilliant shape rotator:

There is a 33-dimensional grid with points at all integer coordinates (x,y,z)(x,y,z) with 1x,y,zn1\leq x,y,z\leq n, and each point has a label associated with it, which is either 'B', 'A', 'P', or 'C'. In this grid, you need to find occurrences of the curly word "BAPC". A curly word "BAPC" is a collection of four points in the grid such that:

  • The labels spell out "BAPC" (in this order).
  • The angle that the triplet "BAP" makes is 9090 degrees: the vectors from B \to A and from A \to P form a 9090-degree angle.
  • The angle that the triplet "APC" makes is 9090 degrees: the vectors from A \to P and from P \to C form a 9090-degree angle.

Note that the two angles do not need to be axis-aligned. As an example, see the third sample case, visualized in Figure L.1.

How many occurrences of the curly word "BAPC" are in the given grid?

입력

The input consists of:

  • One line with an integer nn (1n221\leq n\leq 22), the size of the grid.
  • nn blocks of n+1n+1 lines. Each block of n+1n+1 lines consists of:
    • One line with a hyphen (-), to make the input more human-readable.
    • nn lines with nn characters, each character being either 'B', 'A', 'P', or 'C', representing all labels of one horizontal layer of the 33-dimensional grid.

출력

Output the number of curly words "BAPC" in the 33-dimensional grid.

힌트

Figure L.1: Visualization of the third sample input. In this grid, there are two curly words "BAPC", using the highlighted letters.

예제

예제 1

입력
1
-
B
출력
0

예제 2

입력
2
-
PA
PB
-
CC
PB
출력
2

예제 3

입력
3
-
BBB
BCB
BCB
-
BBC
CBA
BBB
-
BBB
BPB
BBB
출력
2
코드를 제출하려면 로그인하세요.