QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#210756 | #6540. Beautiful Sequence | 275307894a | WA | 1ms | 6040kb | C++14 | 1.1kb | 2023-10-11 19:50:24 | 2023-10-11 19:50:25 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=1e6+5,M=N*4,K=600+5,mod=998244353,Mod=mod-1;const db eps=1e-6;const ll INF=1e18+7;mt19937 rnd(263082);
int n,m,A[N],B[N];
void Solve(){
int i,j;scanf("%d",&n);
for(i=1;i<=n;i++) scanf("%d",&A[i]);sort(A+1,A+n+1);
fill(B+1,B+n+1,0);
m=0;for(i=1;i<=n;i++) m+=(A[i]!=A[i-1]),B[m]++;
int ans=n-(m-1);priority_queue<int> q;
int sum=0;
for(i=m-1;i;i--){
q.emplace(-B[i]-1);
sum+=B[i];ans++;
while(sum>=-q.top()){
sum+=q.top();q.pop();ans--;
}
}
printf("%d\n",ans);
}
int main(){
int t=1;
scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6040kb
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: 6012kb
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'