#P10534. [Opoi 2024] 简谐振动
[Opoi 2024] 简谐振动
Background
You are right, but simple harmonic motion is very beautiful.
However, we are not going to the sea under polygons, so you do not need to maintain the simple harmonic motion of a particle.
Problem Description
Given a digit string , determine whether there exists an integer sequence of length where is odd, such that the values of $A_1 + A_2, A_2 + A_3, \dots, A_{n-1} + A_n, A_n + A_1$, when concatenated in this order, can form .
In particular, if there is a solution such that, during concatenation, inserting zeros as separators between two adjacent terms can still produce , then this solution is also considered valid. All testdata guarantee that has no leading .
Input Format
The first line contains an integer , the number of test cases.
For each test case:
The first line contains an integer .
The second line contains a string .
Output Format
For each test case, if a solution exists, output Yes; otherwise output No. Print each answer on its own line.
3
3
131011
1
5
3
2011
Yes
No
Yes
Hint
Sample Explanation
Explanation for the first sample:
$\begin{matrix} 7&6&4\cr +&+&+\cr 6&4&7\cr ||&||&||\cr 13&10&11\end{matrix}$
Of course, you can also say:
$\begin{matrix} 71&60&-60\cr +&+&+\cr 60&-60&71\cr ||&||&||\cr 131&0&11\end{matrix}$
The construction is not unique.
Explanation for the second sample:
If there is a solution, then . But the problem states that is an integer sequence, so there is no solution.
Explanation for the third sample:
$\begin{matrix} 1&&1&0\cr +&&+&+\cr 1&&0&1\cr ||&&||&||\cr 2&0&1&1\end{matrix}$
In this solution, there are zeros used as separators in the middle, which meets the requirement, so output
Yes.
Constraints
For of the testdata: , , .
For of the testdata: . It is guaranteed that and , , and is odd.
Translated by ChatGPT 5