95pts 求条
查看原帖
95pts 求条
1495442
PFzyf楼主2025/1/23 17:57

求条 95pts WA13

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long

using namespace std;
const int N=1000001;
int n,k;
int a[N];
char s[N];
int check(ll p)
{
	int tx=0,ty=0,tmp=k;
	for(int i=1;i<=n;i++)
	{
	  if(a[i]==0) tx++;
	  else ty++;
	  ll v=tx*ty;
	  if(v>p) {tmp--; tx=0; ty=0; i--;}
	  if(tmp==0) return false;
	}
	return true;
}
int main()	
{
	scanf("%d%d",&n,&k);
    scanf("%s",s+1);
	for(int i=1;i<=n;i++)
	  a[i]=s[i]-'0';
	ll l=0,r=1e15;
	while(l<=r)
	{
	  ll mid=l+r>>1;
	  if(check(mid)) r=mid-1;
	  else l=mid+1;
	}
	cout<<l;
	return 0;
}

2025/1/23 17:57
加载中...