QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#684747 | #9258. Huawei Frequencies Selection | xw75pyh | WA | 1ms | 8552kb | C++14 | 1.6kb | 2024-10-28 15:33:28 | 2024-10-28 15:33:28 |
Judging History
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[0]=0;
int mx=-1;
for(int i=1,j=-1,k=0;i<=n;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.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);
}
write(3);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7952kb
input:
2 2 0 2
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 7524kb
input:
3 1 2 1 1
output:
1
result:
ok answer is '1'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 8552kb
input:
3 2 1 3 0
output:
1
result:
wrong answer expected '2', found '1'