QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#425136#6540. Beautiful SequenceCharlieVinnieWA 0ms3696kbC++201.3kb2024-05-29 22:30:242024-05-29 22:30:24

Judging History

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

  • [2024-05-29 22:30:24]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3696kb
  • [2024-05-29 22:30:24]
  • 提交

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(x==1){
            flg=1;
        }
        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{
            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: 0ms
memory: 3692kb

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: 0
Accepted
time: 0ms
memory: 3696kb

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
17

result:

ok 2 number(s): "4 17"

Test #3:

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

input:

300
14
1 1 1 2 2 2 3 3 3 4 5 5 6 6
14
1 1 1 2 2 3 3 4 4 5 5 6 7 7
14
1 1 2 2 3 4 4 4 5 5 5 6 6 6
14
1 1 2 2 3 3 3 4 5 5 5 6 6 6
14
1 1 1 1 1 1 2 2 2 2 2 3 3 3
14
1 1 1 1 1 1 1 1 1 1 1 1 1 1
14
1 2 2 3 4 5 5 6 6 6 7 8 8 8
14
1 2 2 2 2 2 3 4 5 6 7 8 9 10
14
1 2 2 3 4 4 4 5 6 6 6 6 6 7
14
1 1 2 2 2 3 3...

output:

10
9
11
11
12
14
10
9
11
11
9
10
10
9
11
11
11
9
9
12
10
9
10
10
11
10
11
11
11
11
10
8
10
10
10
10
11
13
10
12
11
11
9
10
9
11
11
10
10
8
11
10
11
9
10
10
10
10
11
11
12
9
10
10
10
10
9
10
11
11
10
10
10
10
11
10
10
10
10
9
9
10
8
11
9
11
10
11
11
12
9
9
10
9
12
11
10
11
10
10
11
10
10
9
10
9
10
10...

result:

wrong answer 174th numbers differ - expected: '10', found: '9'