-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvasyaAndMultisets.cpp
90 lines (69 loc) · 1.74 KB
/
vasyaAndMultisets.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
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
/*
* http://codeforces.com/problemset/problem/1051/C
*/
int main(){
int n;
int countA =0, countB =0;
int prettyNumbers = 0;
cin >> n;
vector<int> count(101, 0);
vector< queue<char> >qs(101);
vector<int>input;
int temp;
for(int i =0; i < n; i++){
cin >> temp;
count[temp]++;
input.push_back(temp);
}
for(int i =0; i < n; i++){
if(count[input[i]] == 1){
prettyNumbers++;
}
}
for(int i =0; i< 101; i++){
if(count[i] == 0) continue;
if(count[i] > 2 && prettyNumbers%2 != 0){
prettyNumbers++;
if(countA < countB){
countA++;
qs[i].push('A');
for(int j =0; j < count[i]-1; j++){
qs[i].push('B');
}
}else{
qs[i].push('B');
countB++;
for(int j =0; j < count[i]-1; j++){
qs[i].push('A');
}
}
}else{
if(countA < countB){
for(int j =0; j < count[i]; j++){
qs[i].push('A');
}
if(count[i] == 1)countA++;
}else{
for(int j =0; j < count[i]; j++){
qs[i].push('B');
}
if(count[i] == 1)countB++;
}
}
}
if(countA == countB){
cout << "YES" << endl;
for(int i =0; i< input.size(); i++){
cout << qs[input[i]].front();
qs[input[i]].pop();
}
cout << endl;
return 0;
}
cout << "NO" << endl;
return 0;
}