rt。
普及第三课上午 T3。
#pragma GCC optimize("O0") // 吸氧优化,但是中毒了!!!
#include <cstring>
#include <iostream>
#include <string>
const int N = 1e5 + 10;
int T, sum0[N], sum1[N];
std::string s;
bool check(int n);
int main(void)
{
std::cin >> T;
while (T--)
{
std::cin >> s;
sum0[0] = (s[0] == '0');
sum1[0] = (s[0] == '1');
for (int i = 1; i < s.length(); i++)
{
sum0[i] = sum0[i - 1] + (s[i] == '0');
sum1[i] = sum1[i - 1] + (s[i] == '1');
}
int l = -1, r = s.length() + 1;
while (l + 1 < r)
{
int mid = (l + r) >> 1;
if (check(mid))
{
r = mid;
}
else
{
l = mid;
}
}
std::cout << r << std::endl;
}
#define _ 0
return ~~(0^_^0);
#undef _
}
bool check(int n)
{
for (int i = s.length() - 1, j = s.length() - 1; i >= 0; i--)
{
while (sum0[i] - sum0[j - 1] <= n && j > 0)
{
j--;
}
if (sum1[j - 1] + sum1[s.length() - 1] - sum1[i] <= n)
{
return true;
}
}
return false;
}