Logo zibenlun 的博客

博客

AT_abc332_c

...
zibenlun
2025-12-01 12:58:17
分块好啊

本文章由 WyOJ Shojo 从洛谷专栏拉取,原发布时间为 2023-12-11 22:07:55

有没有好心人给我买一件ATcoder的T恤衫~

Solution

纯模拟,做法很简单,能穿普通 T-shirt 就穿普通的,并且在每一次洗衣服之前以及最后一天之后,统计一下距离上一次洗衣服时需要多少件,取一个最大值就行了。

CODE

#include<bits\/stdc++.h>
using namespace std;
inline long long read() {
	long long s=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') {
		s=(s<<3)+(s<<1)+(ch^48);
		ch=getchar();
	}
	return s;
}
inline void write(long long x) {
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x\/10);
	putchar(x%10+'0');
}
int n,m;
char s[100005];
int main(){
\/\/	freopen(".in","r",stdin);
\/\/	freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>(s+1);
	int maxx=0;
	int sum=0;
	int summ=0;
	for(int i=1;i<=n;i++){
		if(s[i]=='1'){
			if(summ<m){
				summ++;
			}
			else {
				sum++;
			}
		}
		else if(s[i]=='0'){
			maxx=max(maxx,sum);
			sum=0;
			summ=0;
		}
		else {
			sum++;
		}
	}
	maxx=max(maxx,sum);
	cout<<maxx;
	return 0;
}

评论

暂无评论

发表评论

可以用@mike来提到mike这个用户,mike会被高亮显示。如果你真的想打“@”这个字符,请用“@@”。