QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#479930#4617. Arithmetic SubsequencemasterhuangAC ✓25ms3840kbC++20681b2024-07-15 22:09:222024-07-15 22:09:24

Judging History

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

  • [2024-07-15 22:09:24]
  • 评测
  • 测评结果:AC
  • 用时:25ms
  • 内存:3840kb
  • [2024-07-15 22:09:22]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
const int N=5005;
int T,n,a[N];
unordered_map<int,int>c;
inline bool cmp(int x,int y)
{
	for(int i=0;i<=__lg(max(x,y));i++)
		if((x^y)>>i&1) return (x>>i&1)>(y>>i&1);
	return 1;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>T;
	while(T--)
	{
		cin>>n;bool ok=1;c.clear();
		for(int i=1;i<=n;i++) cin>>a[i],c[a[i]]++;
		for(auto [x,y]:c) if(y>2){ok=0;break;}
		if(!ok){cout<<"NO\n";continue;}
		sort(a+1,a+1+n,cmp);cout<<"YES\n";
		for(int i=1;i<=n;i++) cout<<a[i]<<" ";cout<<"\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 25ms
memory: 3840kb

input:

25
4
3 6 8 9
5
1 1 1 1 1
5000
204869248 184063453 335277313 805198752 988635160 266844506 494544568 842685418 516257494 110006739 727397507 931812983 898605116 670474885 536302721 818724782 251547299 883494814 479828194 573135914 408419766 283100869 472145517 996777784 393702645 555881361 835407611 ...

output:

YES
3 9 6 8 
NO
YES
997457919 28540927 168284159 392485887 30561279 618477055 33609215 425276159 80450303 766389503 20466943 937493759 234127231 266813311 315469695 642043775 876816255 905333631 953092479 284389759 786805119 126109311 668253311 907828351 548105343 857108607 187678847 689291391 92700...

result:

ok