Untitled

mail@pastecode.io avatar
unknown
plain_text
4 months ago
938 B
8
Indexable
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
const int N = 1e9 + 7;

template <typename T>
istream& operator>>(istream& in, vector<T>& a){for(T& x : a){in >> x;}return in;}

void solve()
{
	int n;
	cin>>n;
	vector<int>a(n);
	cin>>a;
	vector<int>b(n);
	vector<int>vis(10000);
	for(int i=0; i<n; i++)b[i]=1;
	if(n<4){cout<<-1<<endl;return;}
	int count=0;
	bool ok=true;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			if(!vis[i]){
			if(a[i]==a[j]){
				vis[j]=1;
				count++;
				if(count==1)b[i]=2;
				else b[i]=3;
				break;
			}
		}
		}
		if(count>2){
			ok=false;
			break;
		}
	}
	cout<<count<<endl;
	if(count!=2)ok=false;
	if(ok){
		for(int i=0; i<n; i++)cout<<b[i]<<" ";
		cout<<endl;
	}
	else cout<<-1<<endl;
	
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int t = 1;
	cin >> t;
	while (t--)
		solve();
}
Leave a Comment