QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#423284#6540. Beautiful SequencewdnmdwrnmmpWA 1ms3808kbC++141.3kb2024-05-27 22:04:412024-05-27 22:04:41

Judging History

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

  • [2024-05-27 22:04:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3808kb
  • [2024-05-27 22:04:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<int> vi;
typedef pair<int,int> pi;

void solve(){
    int n; cin>>n;
    vi a(n+1);
    rep(i,0,n-1){
        cin>>a[i];
    }
    sort(a.begin(), a.begin()+n);
    a[n]=-1;
    int cnt=1, r=0;;
    priority_queue<int, vi, greater<int>> Q;
    rep(i,1,n){
        if(a[i]!=a[i-1]){
            if(cnt!=i){
                Q.push(cnt);
                if(r){
                    r--;
                }
                else{
                    int x=Q.top();
                    Q.pop();
                    if(x>=0){
                        Q.push(x-1);
                    }
                }
            }
            else{
                r=cnt+1;
            }
            cnt=0;
        }
        cnt++;
    }
    int ans=0;
    while(!Q.empty()){
        ans+= Q.top();
        Q.pop();
    }
    cout<<ans<<'\n';
}
signed main(){
    #ifndef ONLINE_JUDGE
    assert(freopen(".in","r",stdin));
    // assert(freopen(".out","w",stdout));
    #endif
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int t; cin>>t;
    while(t--){
        solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3520kb

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: 1ms
memory: 3808kb

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
14

result:

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