/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Wrong Answer 6ms 576.0 KiB
#3 Wrong Answer 7ms 764.0 KiB

Code

#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
#define pi 2*acos(0.0)
#define f first
#define s second
#define inf INT_MAX
#define MXN 500001
#define endl "\n"
#define eps 1e-6
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rev(x) x.rbegin(), x.rend()
#define spc(x) cout << fixed << setprecision(x)
#define fastio {ios_base::sync_with_stdio(false); cin.tie(NULL);}
#define test ll t; cin >> t; while (t--)

typedef long long ll;
using namespace std;

void solve()
{
   ll n,k;
   cin>>n>>k;


   string s; cin>>s;

   ll cnt=0;
   vector<ll> v;
   for(int i=0;i<s.size();i++){
        if(s[i]=='1'){
            cnt++;
        } 
         else{
               if(cnt>0){
                  v.pb(cnt);
               }
               cnt=0;
         }
   }
   if(cnt>0){
      v.pb(cnt);
   }
   k++;

   ll left = 0;
   ll right = 0;

   ll mx=0;
   ll sum=0;
   while(right<v.size()){
         sum+=v[right];
         if(right-left+1>k){
               sum-=v[left];
               left++;
         }
         right++;
         mx = max(mx,sum);
   }
   cout<<mx<<endl;
}
int32_t main()
{
   fastio
   int t = 1;
   cin >> t;
   while (t--) {
      solve();
   }
   return 0;
}

Information

Submit By
Type
Submission
Problem
P1159 Binary String
Contest
Brain Booster #8
Language
C++17 (G++ 13.2.0)
Submit At
2025-02-17 14:50:25
Judged At
2025-02-17 14:50:25
Judged By
Score
0
Total Time
7ms
Peak Memory
764.0 KiB