QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#423284 | #6540. Beautiful Sequence | wdnmdwrnmmp | WA | 1ms | 3808kb | C++14 | 1.3kb | 2024-05-27 22:04:41 | 2024-05-27 22:04:41 |
Judging History
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();
}
}
Details
Tip: Click on the bar to expand more detailed information
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'