QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#664075#7880. Streak ManipulationB1ueqwqWA 1ms7740kbC++141.0kb2024-10-21 19:08:332024-10-21 19:08:33

Judging History

你现在查看的是最新测评结果

  • [2024-10-21 19:08:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7740kb
  • [2024-10-21 19:08:33]
  • 提交

answer

#include <bits/stdc++.h>
typedef long long ll; 
using namespace std;
ll n,m,k;
string ch;
const ll maxn=2e5+5;
ll sum[maxn];
ll nxt[maxn];
ll f[maxn][10];
const ll INF=maxn;
bool check(ll len){
	for(ll i=1;i<=n;i++){
		ll l=i,r=l+len-1;
		if(r>n)
			f[i][1]=INF;
		else
			f[i][1]=sum[r]-sum[l-1];
	}
	for(ll st=2;st<=k;st++){
		ll minn=INF;
		for(ll i=n;i>=1;i--){
			ll l=i,r=l+len-1;
			ll ll=nxt[r+1]+1;
			if(r+1<=n&&ll<=n)
				minn=min(minn,f[ll][st-1]);
			if(r>n)
				f[i][st]=INF;
			else{
				f[i][st]=minn+sum[r]-sum[l-1];
			}
		}
	}
	return f[1][k]<=m;
}
int main(){
	cin>>n>>m>>k;
	cin>>ch;
	for(ll i=1;i<=n;i++){
		char tmp=ch[i-1];
		if(tmp=='0')
			sum[i]=1;
		else
			sum[i]=0;
		sum[i]+=sum[i-1];
	}
	nxt[n+1]=n+1;
	for(ll i=n;i>=1;i--){
		char tmp=ch[i-1];
		if(tmp=='0')
			nxt[i]=i;
		else
			nxt[i]=nxt[i+1];
	}
	ll l=1,r=n;
	ll ans=-1;
	while(l<=r){
		ll mid=(r-l>>1)+l;
		if(check(mid)){
			l=mid+1;
			ans=mid;
		}
		else
			r=mid-1;
	}
	cout<<ans<<endl;
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5712kb

input:

8 3 2
10110110

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

12 3 3
100100010011

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5768kb

input:

4 4 4
0000

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 7740kb

input:

1000 200 5
0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...

output:

96

result:

wrong answer 1st numbers differ - expected: '99', found: '96'