AT_abc332_c

· · 题解

有没有好心人给我买一件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;
}