QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#168829 | #6540. Beautiful Sequence | PhantomThreshold | WA | 4ms | 3484kb | C++20 | 620b | 2023-09-08 23:20:47 | 2023-09-08 23:20:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int maxn=300000;
int T;
int n;
int a[maxn+50];
int main(){
ios_base::sync_with_stdio(false);
cin >> T;
for (;T--;){
cin >> n;
for (int i=1;i<=n;i++) cin >> a[i];
map<int,int> dict;
for (int i=1;i<=n;i++) dict[a[i]]++;
priority_queue<pii,vector<pii>,greater<pii>> q;
int v=0;
for (auto [x,cnt]:dict){
q.emplace(cnt,x);
while (q.size()>v+1){
auto qf=q.top();
q.pop();
if (qf.first!=1) q.emplace(qf.first-1,qf.second);
v++;
}
}
cout << n-v << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3484kb
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: 3404kb
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: 4ms
memory: 3484kb
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 10 11 11 12 14 10 9 11 11 9 10 10 9 11 11 11 10 10 12 10 9 10 10 11 11 11 11 11 11 10 9 10 10 10 10 11 13 11 12 11 11 9 10 10 11 11 10 10 9 11 10 11 10 10 10 10 10 11 11 12 10 10 10 10 10 9 11 11 11 10 10 10 10 11 10 11 10 10 10 9 10 9 11 9 12 10 11 11 12 9 9 10 9 12 11 10 12 10 10 11 10 10 9 11 ...
result:
wrong answer 2nd numbers differ - expected: '9', found: '10'