QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#203369#6310. Dining ProfessorshqyangRE 1ms3596kbC++201.2kb2023-10-06 16:58:002023-10-06 16:58:00

Judging History

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

  • [2023-10-06 16:58:00]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3596kb
  • [2023-10-06 16:58:00]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>

using namespace std;

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*10+ch-'0',ch=getchar();}
    return x*f;
}

int n,k;
const int N=1e5+10;
int a[N],ans;
vector<int>q;

//i mod n + 1
//((i + n - 2) mod n) + 1


struct ST{
    int num;
    bool operator<(const ST &W){
        return num>W.num;
    }
}st[N];

int main(){
    n=read(),k=read();
    for(int i=1;i<=n;i++){
        a[i]=read();
        if(a[i]){
            ans+=3;
        }
        a[i+n]=a[i];
        a[i+n+n]=a[i+n];
        //if(a[i]==0){
        //    q.push_back(i);
        //}
    }
    
    int bula=n-k;
    
    
    int res=0;
    for(int i=1+n;i<=2*n;i++){
            
        res++;
        st[res].num=(a[i-1]==0)+(a[i]==0)+(a[i+1]==0);
        //q.push_back(i);

    }
    
    sort(st+1,st+1+res);
    
    for(int i=1;i<=bula;i++){
        ans+=st[i].num;
    }
    
    cout<<ans<<endl;
    //for(int i=1;i<=res;i++){
    //    cout<<st[i].num<<" ";
    //}
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 2
1 0 1 0 1

output:

13

result:

ok 1 number(s): "13"

Test #2:

score: -100
Runtime Error

input:

100000 33292
1 1 1 1 0 1 1 0 0 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 0 1 1 1 0 1 0 0 1 1 0 0 0 1 0 1 0 1 0 1 1 0 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 1 1 1 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 1 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 0 0...

output:


result: