5445.Dihedral Group

时间限制:1s 内存限制:256MB

In mathematics, the dihedral group $D_n$ is the group of symmetries of a regular $n$-gon. Rotations and reflections are elements of $D_n$, and in fact all elements of the dihedral group can be expressed as a series of rotations and reflections. Elements of $D_n$ act on the $n$-gon by permuting its vertices.
For example, consider a regular pentagon with vertices initially labeled $1, 3, 5, 4, 2$ (clockwise, starting from the top):
NWZN1ickztRIianKFpEUcY3vl0ITiX5MAKV88Z6N.png

Applying the above three dihedral actions to the pentagon (a rotation, reflection, and then another rotation) produces the following relabelings of the pentagon’s vertices:
$1, 3, 5, 4, 2 → 2, 1, 3, 5, 4 → 2, 4, 5, 3, 1 → 1, 2, 4, 5, 3.$
You are given an arbitrary clockwise labeling of the vertices of a regular $n$-gon using the integers $1$ through $n$, and a second sequence to test. Determine whether it’s possible to apply some series of dihedral actions to the $n$-gon so that the test sequence appears as a contiguous clockwise sequence of vertex labels on the transformed polygon.

输入格式(从终端/标准输入读取)

The first line of input has two integers $n$ and $m, (1 ≤ m ≤ n ≤ 5 · 10^4 )$ where $n$ is the number of vertices of the polygon and m is the length of the sequence to be tested.

The next line contains $n$ space-separated integers $d (1 ≤ d ≤ n)$. This is the initial labeling of the polygon vertices. It is guaranteed that each integer from $1$ to $n$ appears exactly once.

The next line contains $m$ space-separated integers $t (1 ≤ t ≤ n)$. This is the sequence to be tested.

输出格式(输出至终端/标准输出)

Output a single integer, which is $1$ if the test sequence could appear as a contiguous sequence of vertex labels after applying some series of dihedral actions to the initial polygon, and $0$ otherwise.

输入样例1

复制
3 3
1 2 3
1 3 2
 · \n
 · · \n
 · · \n

输出样例1

复制
1
 \n

输入样例2

复制
3 1
1 2 3
1
 · \n
 · · \n
 \n

输出样例2

复制
1
 \n

输入样例3

复制
4 2
1 2 3 4
1 3
 · \n
 · · · \n
 · \n

输出样例3

复制
0
 \n

输入样例4

复制
4 4
1 2 3 4
2 3 4 1
 · \n
 · · · \n
 · · · \n

输出样例4

复制
1
 \n

输入样例5

复制
4 4
1 2 3 4
3 2 1 4
 · \n
 · · · \n
 · · · \n

输出样例5

复制
1
 \n

输入样例6

复制
5 3
1 3 5 4 2
2 1 3
 · \n
 · · · · \n
 · · \n

输出样例6

复制
1
 \n

输入样例7

复制
5 4
1 3 5 4 2
2 1 5 3
 · \n
 · · · · \n
 · · · \n

输出样例7

复制
0
 \n
来源: NAC 2024

提交题解

Please login first.

© 2025 FAQs