#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
const int N = 200010;
int n;
bool check(vector<int> &t)
{
for (int i = 0; i < n; i ++)
{
if(t[i] == 0)
{
return false;
}
}
return true;
}
int main()
{
int t; cin >> t;
while(t --)
{
string s; cin >> n >> s;
for (int k = n; k >= 1; k --)
{
vector<int> t(n, 0), end(n + 1, 0);
for (int i = 0; i < n; i ++) t[i] = s[i] - '0';
int cnt = 0;
for (int i = 0; i < n; i ++)
{
cnt = cnt - end[i];
t[i] = t[i] ^ (cnt&1);
if(t[i]) continue;
if(t[i] == 0 && i + k <= n)
{
end[i + k] ++;
cnt ++;
t[i] = 1;
}
else break;
}
if(check(t))
{
cout << k << endl << endl;
break;
}
}
}
}
938 div3 E
最新推荐文章于 2024-07-13 23:05:26 发布