QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#278888#7880. Streak ManipulationMurphy_WA 1ms5728kbC++141.1kb2023-12-07 22:12:552023-12-07 22:12:56

Judging History

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

  • [2023-12-07 22:12:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5728kb
  • [2023-12-07 22:12:55]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define re register
#define il inline
#define N 200005
using namespace std;
char str[N];
int f[N][6][2],g[N],n,m,k;
bool check(int len) {
	for(int i=0;i<=n;++i) for(int j=0;j<=k;++j) f[i][j][0]=f[i][j][1]=N;
	for(int i=0,s=0;i<=n&&s<len;++i) {if(str[i+1]=='0') s=0;else s++;f[i][0][0]=0;}
	for(int i=1,x=0;i<=n;++i) {
		for(int j=1;j<=k;++j) {
			if(str[i]=='0') f[i][j][0]=min(f[i][j][0],f[i-1][j][1]);
			if(str[i]=='1') f[i][j][0]=f[i-1][j][0];
			if(i>=len) f[i][j][1]=min(f[i-len][j-1][0],f[i-len][j][1])+g[i]-g[i-len];
		}
	}
//	for(int i=0;i<=n;++i) {for(int j=0;j<=k;++j) cout<<f[i][j][0]<<' ';cout<<endl;}cout<<endl;
//	for(int i=0;i<=n;++i) {for(int j=0;j<=k;++j) cout<<f[i][j][1]<<' ';cout<<endl;}cout<<endl;
	
	if(f[n][k][0]<=m||f[n][k][1]<=m) return 1;
	return 0;
}

int main()
{
	cin>>n>>m>>k>>(str+1);
	for(int i=1;i<=n;++i) g[i]=g[i-1]+((str[i]-'0')^1);
	int l=0,r=n;
	while(l<r) {
		int mid=ceil((l+r)/2.0);
//		cout<<l<<':'<<r<<':'<<mid<<endl;
		if(check(mid)) l=mid;
		else r=mid-1; 
	}
	if(!l) cout<<"-1";
	else cout<<l;
	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: -100
Wrong Answer
time: 1ms
memory: 5728kb

input:

12 3 3
100100010011

output:

-1

result:

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