AcWing 562. 壁画
原题链接
中等
作者:
RanPg
,
2024-03-01 20:53:07
,
所有人可见
,
阅读 41
C++ 代码
#include<bits/stdc++.h>
using namespace std;
const int N = 5e6 + 10;
int T;
char str[N];
int s[N];
int op(int n)
{
int res = 0;
for(int i = 1; i <= n; i ++)
s[i] += (s[i - 1] + (str[i] - '0'));
int t = ceil(n * 1.0 / 2.0);
for(int i = 0, j = t; j <= n; i ++, j ++)
res = max(res, s[j] - s[i]);
return res;
}
int main()
{
scanf("%d", &T);
for(int i = 1; i <= T; i ++)
{
memset(s, 0, sizeof s);
int n;
scanf("%d", &n);
scanf("%s", str + 1);
int res = op(n);
printf("Case #%d: %d\n", i, res);
}
return 0;
}