QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#278135#7880. Streak ManipulationVegetable_Dog#WA 5ms13232kbC++14914b2023-12-07 12:45:322023-12-07 12:45:33

Judging History

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

  • [2023-12-07 12:45:33]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:13232kb
  • [2023-12-07 12:45:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define MEM(a,x) memset(a,x,sizeof(a));
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define Rep(i,a,b) for(int i=a;i>=(b);i--)
typedef vector<int> vi;
const int N=2e5+5,inf=1e9;
int n,m,k;
string s;
int dp[6][N];
bool check(int x){
	MEM(dp,0x3f);
	dp[0][0]=0;
	int p=0,cnt=0;
	vi mn(6,inf);mn[0]=0;
	rep(i,1,x+1)cnt+=s[i]=='0';
	rep(i,x+1,n+2){
		rep(j,1,k+1)dp[j][i]=min(dp[j][i],mn[j-1]+cnt+(s[i]=='1'));
		cnt-=(s[++p]=='0'),cnt+=(s[i]=='0');
		rep(j,0,k+1)mn[j]=min(dp[j][p],mn[j]);
	}
	return *min_element(dp[k]+1,dp[k]+n+2)<=m;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n>>m>>k>>s;
	s='0'+s+'0';
	int l=0,r=n;
	while(l<r){
		int md=(l+r+1)/2;
		if(check(md))l=md;
		else r=md-1;
	}
	cout<<(!l?-1:l)<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 13232kb

input:

8 3 2
10110110

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

12 3 3
100100010011

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

4 4 4
0000

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

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

input:

1000 200 5
0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...

output:

99

result:

ok 1 number(s): "99"

Test #5:

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

input:

1000 200 5
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

40

result:

ok 1 number(s): "40"

Test #6:

score: -100
Wrong Answer
time: 3ms
memory: 13032kb

input:

1000 200 5
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

199

result:

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