QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#684753#9258. Huawei Frequencies Selectionxw75pyhWA 2ms9176kbC++141.6kb2024-10-28 15:36:142024-10-28 15:36:15

Judging History

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

  • [2024-10-28 15:36:15]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9176kb
  • [2024-10-28 15:36:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int Maxn=2e2+10;
const int Maxm=1e3+10;
const int N=5e5+10;
const int M=5e5+10;
const int mod=1e9+7;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<3)+(x<<1)+(ch^48);ch=getchar();
	}
	return x*f;
} 
inline void write(int x){
	if(x<0){
		x=-x;putchar('-');
	}
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
inline int ksm(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=ans*a%mod;b>>=1;a=a*a%mod;
	}
	return ans;
} 
int n,k;int a[M];int op;
deque<int>q;int dp[M];
signed main(){
	n=read(),k=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
		if(!a[i])op++;
	}
	if(op>=k){
		write(0);return 0;
	}q.push_back(0);
	memset(dp,-1,sizeof dp);dp[1]=0;
	int mx=-1;
	for(int i=2,j=0,k=0;i<=n+1;i++){
		if(a[i-1]==1){
			while(j<i-1){
				j++;
				mx=max(mx,dp[j]);
			}
		}
		if(a[i-1]==0){
			k=i;
			while(!q.empty()&&q.front()<k){
				q.pop_front();
			}
		}
		dp[i]=mx;
		if(!q.empty()){
			dp[i]=max(dp[i],dp[q.front()]);
		}
		if(dp[i]>=0)dp[i]++;
		while(!q.empty()&&dp[i]>=dp[q.back()]){
			q.pop_back();
		}
		q.push_back(i);
	}
	if(k<=dp[n]){
		write(1);
		return 0;
	}
	int sum=0;
	for(int i=1;i<=n;i++){
		if(a[i]==2){
			sum++;
		}
	}
	if(sum>0){
		write(2);
		return 0;
	}
	int lst=-1;
	int res=0;
	for(int i=1;i<=n;i++){
		if(a[i]<=1){
			if(a[i]!=lst){
				res++;
			}
			lst=a[i];
		}
	}
	if(k>=res){
		write(2);return 0;
	}
	write(3);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 9176kb

input:

2 2
0 2

output:

2

result:

ok answer is '2'

Test #2:

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

input:

3 1
2 1 1

output:

1

result:

ok answer is '1'

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 7580kb

input:

3 2
1 3 0

output:

1

result:

wrong answer expected '2', found '1'