竞赛讨论区 > G题双指针做法86.6分 特判求助!
头像
虽然她送了我玫瑰花
发布于 2022-04-05 12:32
+ 关注

G题双指针做法86.6分 特判求助!

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
long long  cnt[2];
signed main(){
    int n,a,b;
    cin>>n>>a>>b;
    string s;cin>>s;
    
    s=" "+s;
    long long res=0;
    if(a==0&&b==0) {
        
      res++; 
    }
    for(int i=1,j=0;i<=n;i++){
        int t=0;
        if(s[i]=='0') t=0;
        else t=1;
        while(j<n&&(cnt[0]<a||cnt[1]<b) ){
            j++;
            cnt[s[j]-'0']++;
       }
       if((cnt[0]>=a&&cnt[1]>=b))
        res+=n-j+1;
        
        cnt[s[i]-'0']--;
    }        
    
    cout<<res;
    return 0;
}
就这几行代码 但就是不知道怎么弄那个特判 难道不是a=0 b=0 答案数+1吗?

全部评论

(1) 回帖
加载中...
话题 回帖

等你来战

查看全部

热门推荐