-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB. Two Out of Three.cpp
77 lines (67 loc) · 1.16 KB
/
B. Two Out of Three.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//MASHRUF's work
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void ok()
{
int n;
bool con1=false,con2= false;
cin>>n;
vector<int>a(n);
int i,chk=0;
for ( i=0 ;i<n ;i++ ){
cin>>a[i];
}
map<int,int>b;
for(auto it: a)
{
b[it]++;
}
vector<int>c,d;
for(auto it: b)
{
if(it.second>=2){
c.push_back(it.first);
}
}
if(c.size()<2)
{
cout<<-1<<endl;
}
else{
for(auto it: a)
{
if(it == c[0])
{
d.push_back(con1?2:1);
con1 = true;
}
else if(it == c[1])
{
d.push_back(con1?3:1);
con2 = true;
}
else{
d.push_back(1);
}
}
for(auto it:d)
{
if(it>0)
{
cout<<it<<" ";
}
}
}
cout<<endl;
}
int main()
{
int t;
cin>>t;
while(t--)
{
ok();
}
return 0;
}