#P8467. [Aya Round 1 B] 甲(one)

    ID: 9414 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>模拟洛谷原创O2优化枚举洛谷月赛

[Aya Round 1 B] 甲(one)

Problem Description

A sequence SS of length 55 is defined as “good” if and only if there exists a permutation PP of length 55 such that SP11=SP2=SP3+1S_{P_1}-1=S_{P_2}=S_{P_3}+1 and SP4=SP5S_{P_4}=S_{P_5}. Now you are given an integer sequence aa of length 55, satisfying 0ai9(1i5)0\le a_i \le 9(1\le i \le 5). Among them, a1a4a_1 \sim a_4 are given. Determine whether there exists an a5a_5 such that aa is “good”.

Here, a permutation PP of length 55 means a sequence of length 55 in which 1,2,3,4,51,2,3,4,5 each appears exactly once.

Input Format

This problem contains multiple test cases.

  • The first line contains an integer TT, the number of test cases.
  • The next TT lines each contain four integers a1,a2,a3,a4a_1,a_2,a_3,a_4, representing one test case.

Output Format

  • Output TT lines in total. For each test case, if there exists an a5a_5 that satisfies the condition, output 11; otherwise output 00.
5
3 2 8 4
1 2 3 4
1 9 4 9
1 0 0 1
0 0 4 2
1
1
0
0
1

Hint

Additional Samples

  • Sample 22 can be found in the distributed file one2.in/one2.ans\textbf{\textit{one2.in/one2.ans}}. This sample satisfies the constraints of test point 22.
  • Sample 33 can be found in the distributed file one3.in/one3.ans\textbf{\textit{one3.in/one3.ans}}. This sample satisfies the constraints of test point 55.

Sample Explanation

Sample #1

  • For the 11st test case, we can set a5=8a_5=8. Then there exists P={4,1,2,5,3}P=\{4,1,2,5,3\} such that aP11=aP2=aP3+1a_{P_1}-1=a_{P_2}=a_{P_3}+1 and aP4=aP5a_{P_4}=a_{P_5}. Therefore output 11.
  • For the 22nd test case, we can set a5=4a_5=4. Then there exists P={3,2,1,4,5}P=\{3,2,1,4,5\} such that aP11=aP2=aP3+1a_{P_1}-1=a_{P_2}=a_{P_3}+1 and aP4=aP5a_{P_4}=a_{P_5}. Therefore output 11.
  • For the 33rd test case, there is no a5a_5 that can make aa “good”.
$$\begin{aligned} \fcolorbox{black}{#fbb}{3\ \ 2\ \ 8\ \ 4} + \fcolorbox{black}{yellow}{8} &\Rightarrow \fcolorbox{black}{#fbb}{2\ \ 3\ \ 4} + \fcolorbox{black}{yellow}{8\ \ 8}\ {\color{green}\sqrt{}}\\ \fcolorbox{black}{#fbb}{1\ \ 2\ \ 3\ \ 4} + \fcolorbox{black}{yellow}{4} &\Rightarrow \fcolorbox{black}{#fbb}{1\ \ 2\ \ 3} + \fcolorbox{black}{yellow}{4\ \ 4}\ {\color{green}\sqrt{}}\\ \fcolorbox{black}{#fbb}{1\ \ 9\ \ 4\ \ 9} + \begin{cases} \fcolorbox{black}{yellow}{0}\\ \fcolorbox{black}{yellow}{1}\\ \cdots\\ \fcolorbox{black}{yellow}{9} \end{cases}&\Rightarrow {\color{red}\xcancel{\color{black} \begin{cases} \fcolorbox{black}{#fbb}{1\ \ 9\ \ 4\ \ 9\ \ 0}\\ \fcolorbox{black}{#fbb}{1\ \ 9\ \ 4\ \ 9\ \ 1}\\ \cdots\\ \fcolorbox{black}{#fbb}{1\ \ 9\ \ 4\ \ 9\ \ 9} \end{cases}}} \end{aligned}$$

Constraints

$$\def\arraystretch{1.5} \begin{array}{|c|c|c|} \hline \textbf{\textsf{Test Point}} & \bm{{T\le}} & \textbf{\textsf{Special Property}} \cr\hline 1 & 100 & \textbf{A} \cr\hline 2 & 100 & \textbf{B} \cr\hline 3 & 100 & - \cr\hline 4 & 1000 & - \cr\hline 5 & 10^5 & - \cr\hline \end{array}$$
  • Special property A\bf A: a1=a2=a3=a4a_1=a_2=a_3=a_4.
  • Special property B\bf B: a1,a2,a3,a4a_1,a_2,a_3,a_4 are pairwise distinct.

For 100%100\% of the testdata, 1T1051\le T\le 10^5, 0ai90\le a_i \le 9.

Translated by ChatGPT 5