QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#276783#7880. Streak Manipulation117023RE 8ms9888kbC++17970b2023-12-06 10:43:502023-12-06 10:43:51

Judging History

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

  • [2023-12-06 10:43:51]
  • 评测
  • 测评结果:RE
  • 用时:8ms
  • 内存:9888kb
  • [2023-12-06 10:43:50]
  • 提交

answer

#include<bits/stdc++.h> 

using namespace std;
int n,m,k;
string s;
vector<int>sum(100010);
bool check(int mid){
	vector<vector<int>>dp(k+10,vector<int>(100010,0x3f3f3f3f));
	vector<int>M(k+10,0x3f3f3f3f);
	M[0]=0;
	dp[0][0]=0;
	for(int i=mid;i<s.size();i++){
		//if(s[i]!='0')
		for(int j=1;j<=k;j++){
			if(s[i]=='0') dp[j][i]=M[j-1]+sum[i]-sum[i-mid];
			M[j-1]=min(M[j-1],dp[j-1][i-mid]);
		//	cout<<i<<" "<<j<<" "<<dp[j][i]<<" \n"[j==k-1];
		} 
	}
	for(int i=0;i<s.size();i++){
		if(dp[k][i]<=m)
			return 1;
	}
	
	return 0;
}
int main() {
    cin>>n>>m>>k;
    cin>>s;
    //s='0'+s;
    s+='0';
    
    for(int i=0;i<s.size();i++){
    	//if(i!=1) sum[i]+=;
    	sum[i+1]=-(s[i]-'1')+sum[i];
	}
    int l=0,r=1e5+10;
    while(l<r){
    	int mid=l+(r-l)/2;
    	if(check(mid)){
    		l=mid+1;
		}else{
			r=mid;
		}
		//cout<<l<<" "<<r<<endl;
	}
	if(l-1<=0)cout<<-1<<endl;
	else cout<<l-1<<endl;
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 8720kb

input:

8 3 2
10110110

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 3ms
memory: 9036kb

input:

12 3 3
100100010011

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 8ms
memory: 9512kb

input:

4 4 4
0000

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: 0
Accepted
time: 3ms
memory: 9888kb

input:

1000 200 5
0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...

output:

99

result:

ok 1 number(s): "99"

Test #5:

score: 0
Accepted
time: 3ms
memory: 9872kb

input:

1000 200 5
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

40

result:

ok 1 number(s): "40"

Test #6:

score: 0
Accepted
time: 4ms
memory: 9864kb

input:

1000 200 5
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

-1

result:

ok 1 number(s): "-1"

Test #7:

score: -100
Runtime Error

input:

200000 5 3
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:


result: