QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#210550#6540. Beautiful Sequence275307894aWA 1ms6116kbC++141.3kb2023-10-11 16:24:292023-10-11 16:24:29

Judging History

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

  • [2023-10-11 16:24:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6116kb
  • [2023-10-11 16:24:29]
  • 提交

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=0,sum=0,tot=0;
	for(i=1;i<=m;i++){
		if(B[i]>=3) ans+=B[i]-2;
		if(!sum&&B[i]>=2&&tot) tot--,sum+=2;
		if(B[i]>=2&&sum) ans+=min(B[i],2),sum--;
		else{
			if(B[i]==1) sum++,tot&&(sum+=2,tot--);
			else if(B[i]==2) tot++,tot>=3&&(tot-=3,ans+=4);
			else ans++;
		} 
		// cerr<<ans<<' '<<sum<<'\n';
	}
	// cerr<<sum<<'\n';
	if(!sum) ans+=(tot?tot+1:0);
	else ans+=(sum+1+tot*2)/2;
	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: 6116kb

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: 6092kb

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'