QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#425098#6540. Beautiful SequenceCharlieVinnieWA 1ms3784kbC++201.3kb2024-05-29 22:09:502024-05-29 22:09:50

Judging History

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

  • [2024-05-29 22:09:50]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3784kb
  • [2024-05-29 22:09:50]
  • 提交

answer

#include "bits/stdc++.h"
#ifdef DEBUG
#include "PrettyDebug.hpp"
#else
#define debug(...) [](){}()
#define debuga(...) [](){}()
#endif
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
using namespace std; typedef long long ll;
constexpr int N=3e5+6; using pii = pair<int,int>;
int n; map<int,int> a; priority_queue<int,vector<int>,greater<>> q;
void Mian(){
    cin>>n; a.clear(); while(q.size()) q.pop();
    For(i,1,n) { int x; cin>>x; a[x]++; }
    int ans=(--a.end())->second; a.erase(--a.end()); int flg=0;
    for(auto [_,x]:a){
        if(flg){
            ans+=x; q.push(x); flg=0;
        }
        else if(q.size()){
            int u=q.top(); q.pop(); q.push(x);
            ans+=x-1; if(u==1) flg=1; else q.push(u-1);
        }
        else{
            if(x==1) flg=1; else q.push(x-1),ans+=x-1;
        }
    }
    cout<<ans<<'\n';
}
signed main(){
    atexit([](){cerr<<"Time = "<<clock()<<" ms"<<endl;});
    int kase; cin>>kase; while(kase--) Mian();
    return 0;
}

// CONTINUE, NON-STOPPING, FOR CHARLIEY
// START TYPING IF YOU DON'T KNOW WHAT TO DO
// STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING

// Started Coding On: May 29 Wed, 21 : 37 : 16

详细

Test #1:

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

input:

2
6
1 1 2 3 3 4
5
1 2 2 3 3

output:

4
4

result:

ok 2 number(s): "4 4"

Test #2:

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

input:

2
5
1 2 2 3 3
20
1 1 1 1 1 1 4 5 8 8 8 8 9 9 9 9 10 10 10 10

output:

4
16

result:

wrong answer 2nd numbers differ - expected: '17', found: '16'