QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#277990#7880. Streak ManipulationCryingWA 1ms7556kbC++171.2kb2023-12-07 10:26:082023-12-07 10:26:10

Judging History

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

  • [2023-12-07 10:26:10]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7556kb
  • [2023-12-07 10:26:08]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define op(x) ((x&1)?x+1:x-1)
#define odd(x) (x&1)
#define even(x) (!odd(x))
#define lc(x) (x<<1)
#define rc(x) (lc(x)|1)
#define lowbit(x) (x&-x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
using namespace std;
const int MAXN = 2e5+10,INF=1e9;
void tomin(int& x,int y){x=min(x,y);}

int n,m,k;
char s[MAXN];
int sum[MAXN],dp[10][MAXN],nxt[MAXN];

int chk(int x){
	rep(i,0,k)rep(j,0,n)dp[i][j]=INF;
	dp[0][0]=0;
	rep(j,0,k-1){
		rep(i,0,n-1)if(dp[j][i]!=INF){
			int val=dp[j][i];
			tomin(dp[j][i+1],val);
			if(i+x <= n){
				int cnt=sum[i+x]-sum[i]; //花费cnt次操作
				int to=nxt[i+x+1];
				tomin(dp[j+1][to],val+cnt);
			}
		}
	}

	return dp[k][n] <= m;
}

int main(){
	ios::sync_with_stdio(false);cin.tie(0);

	cin>>n>>m>>k>>(s+1);
	rep(i,1,n)sum[i]=sum[i-1]+(s[i]=='0');
	nxt[n+1]=n;
	per(i,n,1){
		if(s[i]=='0')nxt[i]=i;
		else nxt[i]=nxt[i+1];
	}
	int L=1,R=n,ret=-1;
	while(L<=R){
		int mid=(L+R)>>1;
		if(chk(mid)){
			ret=mid;L=mid+1;
		}else{
			R=mid-1;
		}
	}
	cout<<ret<<endl;

    return 0;
}

詳細信息

Test #1:

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

input:

8 3 2
10110110

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

12 3 3
100100010011

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

4 4 4
0000

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

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

input:

1000 200 5
0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...

output:

96

result:

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