Submission #4955761


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF=1e18,MOD=1e9+7;
ll ans_0[100001],ans_1[100001];
int main(){
	ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	ll ptr_0=0,ptr_1=0;
	for(int i=0;i<n;){
		ll sum=0;
		while(i<n&&s[i]=='0'){
			sum++;
			i++;
		}
		if(sum>0){
			ans_0[ptr_0]=sum;
			ptr_0++;
		}
		sum=0;
		while(i<n&&s[i]=='1'){
			sum++;
			i++;
		}
		if(sum>0){
			ans_1[ptr_1]=sum;
			ptr_1++;
		}
	}


	ll ans=0,i,hoge=0,j;
	if(ptr_0<=k)ans=n;
	else if(s[0]=='0'){
		for(i=0;i<ptr_0-k+1;i++){
			hoge=0;
			if(i!=0){
				hoge+=ans_1[i-1];
			}
			for(j=i;j<k+i;j++){
				hoge+=ans_0[j];
				hoge+=ans_1[j];
			}
			ans=max(ans,hoge);
		}
	}
	else{
		for(i=0;i<ptr_0-k+1;i++){
			hoge=0;
			for(j=i;j<k+i;j++){
				hoge+=ans_0[j];
				hoge+=ans_1[j];
			}
			hoge+=ans_1[j];
			ans=max(ans,hoge);
		}
	}
	cout<<ans<<endl;

}

Submission Info

Submission Time
Task D - Handstand
User yudegaki
Language C++14 (GCC 5.4.1)
Score 400
Code Size 934 Byte
Status AC
Exec Time 422 ms
Memory 1280 KB

Judge Result

Set Name All Sample
Score / Max Score 400 / 400 0 / 0
Status
AC × 18
AC × 3
Set Name Test Cases
All sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15
Sample sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
sample_01 AC 1 ms 256 KB
sample_02 AC 1 ms 256 KB
sample_03 AC 1 ms 256 KB
testcase_01 AC 2 ms 384 KB
testcase_02 AC 3 ms 384 KB
testcase_03 AC 6 ms 896 KB
testcase_04 AC 1 ms 256 KB
testcase_05 AC 5 ms 1280 KB
testcase_06 AC 268 ms 1280 KB
testcase_07 AC 415 ms 1280 KB
testcase_08 AC 401 ms 1280 KB
testcase_09 AC 422 ms 1280 KB
testcase_10 AC 4 ms 512 KB
testcase_11 AC 3 ms 384 KB
testcase_12 AC 3 ms 384 KB
testcase_13 AC 4 ms 512 KB
testcase_14 AC 4 ms 512 KB
testcase_15 AC 1 ms 256 KB