#P10920. 宇宙射线

宇宙射线

Background

Thanks to

https://www.luogu.com.cn/user/399762
thening the testdata.

Cosmic rays change things all the time /fn.

Problem Description

Given a binary string ss of length nn, you need to find the longest substring whose length is even and whose first half is exactly the same as its second half.

However, due to cosmic ray attacks on this string, the values at some positions have become unknown.

You may treat each unknown value as either 00 or 11. Under this condition, find the length of the longest such substring.

This problem has multiple test cases.

Input Format

The first line contains a positive integer tt, the number of test cases.

The next 2t2t lines describe the test cases, where every two lines form one test case. For each test case, the first line contains a positive integer nn, the length of the string, and the next line contains a string ss of length nn.

Output Format

Output tt lines. Each line contains a non-negative integer, the answer for the ii-th test case. Since the length of the substring must be even, you only need to output the result of dividing its length by 22.

2
10
0110011010
6
01?0?0
4
3

Hint

This problem uses bundled tests.

Subtask\text{Subtask} Score n,tn,t Special Property
11 1010 n≤10,t=500n\le 10,t=500 No special constraints
22 n≤1000,t=1n\le1000,t=1
33 n≤1000,t=1000n\le 1000,t=1000 AA
44 No special constraints
55 n≤104,t=10n\le 10^4,t=10
66 n≤104,t=50n\le 10^4,t=50
77 2020 n≤5×104,t=2n\le 5\times 10^4,t=2
88 1515 n≤105,t=1n\le 10^5,t=1
99 55 n≤105,t=5n\le 10^5,t=5

AA: It is guaranteed that ss contains no character ?.

It is guaranteed that the string consists only of the three characters 0, 1, and ?, and that 1≤n≤1051\le n\le 10^5.

Translated by ChatGPT 5