QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#684755#9258. Huawei Frequencies Selectionxw75pyhRE 2ms9488kbC++141.6kb2024-10-28 15:37:372024-10-28 15:37:37

Judging History

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

  • [2024-10-28 15:37:37]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:9488kb
  • [2024-10-28 15:37:37]
  • 提交

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+1]){
		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: 9440kb

input:

2 2
0 2

output:

2

result:

ok answer is '2'

Test #2:

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

input:

3 1
2 1 1

output:

1

result:

ok answer is '1'

Test #3:

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

input:

3 2
1 3 0

output:

2

result:

ok answer is '2'

Test #4:

score: 0
Accepted
time: 2ms
memory: 9488kb

input:

20 15
1 2 2 0 3 3 2 2 2 0 1 1 2 1 3 1 0 2 2 1

output:

1

result:

ok answer is '1'

Test #5:

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

input:

9 4
0 0 2 1 3 1 3 0 3

output:

1

result:

ok answer is '1'

Test #6:

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

input:

19 17
1 0 0 3 0 0 2 3 1 0 3 3 3 1 3 0 0 3 1

output:

2

result:

ok answer is '2'

Test #7:

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

input:

17 15
0 0 3 0 1 1 2 1 2 1 1 1 3 0 0 1 0

output:

2

result:

ok answer is '2'

Test #8:

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

input:

6 5
2 1 3 0 1 0

output:

2

result:

ok answer is '2'

Test #9:

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

input:

16 12
0 2 0 1 2 0 0 0 1 3 3 0 1 0 3 1

output:

2

result:

ok answer is '2'

Test #10:

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

input:

15 9
0 2 2 1 2 0 3 3 1 0 1 1 1 0 1

output:

2

result:

ok answer is '2'

Test #11:

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

input:

8 6
0 0 0 1 0 1 0 1

output:

2

result:

ok answer is '2'

Test #12:

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

input:

10 6
1 0 0 1 0 1 0 3 3 0

output:

2

result:

ok answer is '2'

Test #13:

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

input:

1 1
0

output:

0

result:

ok answer is '0'

Test #14:

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

input:

1 1
1

output:

1

result:

ok answer is '1'

Test #15:

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

input:

7 4
0 1 0 2 1 3 0

output:

2

result:

ok answer is '2'

Test #16:

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

input:

8 5
1 0 1 0 2 1 3 0

output:

2

result:

ok answer is '2'

Test #17:

score: -100
Runtime Error

input:

1000000 1000000
507624 225615 645997 324384 930930 165669 488080 968655 530722 293286 929521 65826 242278 483915 447838 683484 757911 811652 223115 648468 287602 113125 150435 645440 413280 788127 48622 967532 334599 130555 888316 315597 102200 535955 54735 505596 746579 99783 536797 245479 758694 9...

output:


result: