QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#684863#9258. Huawei Frequencies SelectionS00021WA 3ms16208kbC++141.3kb2024-10-28 16:16:272024-10-28 16:16:28

Judging History

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

  • [2024-10-28 16:16:28]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:16208kb
  • [2024-10-28 16:16:27]
  • 提交

answer

#include<bits/stdc++.h>
#define N 2000005
#define INF 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define MP make_pair
#define lb(x) ((x)&-(x))
using namespace std;
int n,K,a[N],f[N];
struct BIT1{ int T[N]={0};
	void cl(){for(int i=0;i<=n+1;i++) T[i]=-INF;}
	void add(int x,int d){x++; for(int i=x;i<=n+1;i+=lb(i)) T[i]=max(T[i],d);}
	int ask(int x){ if(x<0) return -INF;
		x++; int ret=-INF; for(int i=x;i;i-=lb(i)) ret=max(ret,T[i]); return ret;} 
}T1;
struct BIT2{ int T[N]={0};
	void cl(){for(int i=0;i<=n+1;i++) T[i]=-INF;}
	void add(int x,int d){x++; for(int i=x;i;i-=lb(i)) T[i]=max(T[i],d);}
	int ask(int x){ if(x<0) return -INF;
		x++; int ret=-INF; for(int i=x;i<=n+1;i+=lb(i)) ret=max(ret,T[i]); return ret;}
}T2;
signed main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	scanf("%d%d",&n,&K); int c0=0,c00=0;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),c00+=(a[i]>0),c0+=(a[i]==0);
	if(c0>=K) return !printf("0");
	memset(f,0xcf,sizeof(f));
	f[0]=0,T1.cl(),T2.cl(),T1.add(0,0),T2.add(0,0);
	for(int i=1,m0=0,m1=0;i<=n;i++){
		if(a[i]==0) m0=i; if(a[i]==1) m1=i;
		if(m0&&m1) f[i]=max(f[i],T1.ask(min(m0,m1)-1)+1);
		f[i]=max(f[i],T2.ask(max(m0,m1))+1);
		if(!m0&&!m1) f[i]=i;
		T1.add(i,f[i]),T2.add(i,f[i]);
	}if(f[n]>=K||c00==n) return !printf("1");
	return !printf("2");
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 16128kb

input:

2 2
0 2

output:

2

result:

ok answer is '2'

Test #2:

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

input:

3 1
2 1 1

output:

1

result:

ok answer is '1'

Test #3:

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

input:

3 2
1 3 0

output:

2

result:

ok answer is '2'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 16080kb

input:

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

output:

2

result:

wrong answer expected '1', found '2'