#P15564. [CCPC 2025 哈尔滨站] 连通的正三角形
[CCPC 2025 哈尔滨站] 连通的正三角形
Problem Description
Town A has intersections. These intersections are connected by paths, forming an equilateral triangle whose side length contains roads. The case is shown in the figure below.
:::align{center}
:::
These paths can be divided into three directions: left-slanted, horizontal, and right-slanted. Each direction contains paths. In each direction, the -th path consists of roads.
For example, when :
- The left-slanted paths, ordered by the number of roads from small to large, are , , $(1\leftrightarrow2\leftrightarrow4\leftrightarrow7)$.
- The horizontal paths, ordered by the number of roads from small to large, are , , $(7\leftrightarrow8\leftrightarrow9\leftrightarrow10)$.
- The right-slanted paths, ordered by the number of roads from small to large, are , , $(1\leftrightarrow3\leftrightarrow6\leftrightarrow10)$.
We call three distinct intersections an “equilateral triangle” triple of positive integer length if and only if, after arbitrarily reordering , one of the following holds:
- Starting from , go through left-slanted roads to reach ;
- Starting from , go through horizontal roads to reach ;
- Starting from , go through right-slanted roads to reach .
Or:
- Starting from , go through right-slanted roads to reach ;
- Starting from , go through horizontal roads to reach ;
- Starting from , go through left-slanted roads to reach .
For example, in the figure above, and are “equilateral triangle” triples, while is not.
To reduce traffic congestion, Town A decides to assign a direction to every road. After directing the roads, each road has a unique fixed direction, and all roads on the same path share the same direction.
The figure below shows one possible orientation (corresponding to the third test case of Sample 1).
:::align{center}
:::
We call three distinct intersections a “connected equilateral triangle” triple if and only if they form an “equilateral triangle” triple of positive integer length in the graph, and they can reach each other using only the roads that form this “equilateral triangle” triple. For example, in the figure above:
- is a “connected equilateral triangle” triple, because it is not only an “equilateral triangle” triple, but also they can reach each other using only the roads of that triangle .
- is not a “connected equilateral triangle” triple, because it is not an “equilateral triangle” triple.
- is not a “connected equilateral triangle” triple, because although it is an “equilateral triangle” triple, they cannot reach each other using only the roads of that triangle .
Now you are given the directions of all directed paths. Ask how many “connected equilateral triangle” triples there are in this graph.
Input Format
This problem contains multiple test cases. The first line contains an integer (), indicating the number of test cases.
Then the test cases follow. For each test case:
The first line contains an integer (), indicating the size of the equilateral triangle.
The second line contains a string of length , where . If , it means the direction of the left-slanted path consisting of roads is from upper-right to lower-left, and vice versa.
The third line contains a string of length , where . If , it means the direction of the horizontal path consisting of roads is from left to right, and vice versa.
The fourth line contains a string of length , where . If , it means the direction of the right-slanted path consisting of roads is from lower-right to upper-left, and vice versa.
It is guaranteed that the sum of over all test cases does not exceed .
Output Format
For each test case, output one integer, representing the number of “connected equilateral triangle” triples.
3
1
0
0
0
1
0
0
1
3
010
100
001
1
0
4
1
4
0011
1100
0011
6
Hint
In Sample 1, the graph of the first test case is shown below.
:::align{center}
:::
In Sample 1, the graph of the second test case is shown below.
:::align{center}
:::
In Sample 1, the “connected equilateral triangle” triples in the third test case are:
- ;
- ;
- ;
- .
Translated by ChatGPT 5