-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy path1051C - Vasya and Multisets.cpp
75 lines (66 loc) · 1.08 KB
/
1051C - Vasya and Multisets.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
/*Saurav Paul*/
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n; scanf("%d",&n);
vector<int> v(n) , rem(105);
string ans = "";
for(int i = 0 ; i < n ; i++ ) ans += 'x';
for(int i = 0 ;i < n; i++){
int a ; scanf("%d",&a);
v[i] = a;
rem[a] ++;
}
int a = 0 , b = 0;
for(int i = 0 ; i < n; i++){
if(rem[v[i]] == 1){
if(a < b ){
a ++;
ans[i] = 'A' ;
}
else{
b ++;
ans[i] = 'B' ;
}
}
}
bool ok = (a == b) ;
for(int i = 0 ; i < n; i++ ){
if(rem[v[i]] == -1 )
ans[i] = 'A' ;
else if(rem[v[i]] == -2 )
ans[i]= 'B' ;
else if(ans[i] == 'x'){
if(ok == false){
if(rem[v[i]] == 2){
rem[v[i]] =-1;
ans[i] = 'A' ;
continue ;
}
bool temp = false;
if( a < b ){
ans[i] = 'A' ;
a ++;
temp = true;
}
else{
ans[i] = 'B' ;
b ++;
}
ok = true ;
rem [ v[i] ] = (!temp ? -1 : -2 ) ;
}
else{
rem[v[i]] = -1;
ans[i] = 'A' ;
}
}
}
if(a==b)
printf("YES\n%s\n",ans.c_str() ) ;
else
puts("NO");
return 0;
}