QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#664093#7880. Streak ManipulationB1ueqwqWA 1ms5792kbC++141.1kb2024-10-21 19:12:312024-10-21 19:12:36

Judging History

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

  • [2024-10-21 19:12:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5792kb
  • [2024-10-21 19:12:31]
  • 提交

answer

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

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5708kb

input:

8 3 2
10110110

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

12 3 3
100100010011

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

4 4 4
0000

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 5792kb

input:

1000 200 5
0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...

output:

96

result:

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