fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int long long
  6. #define nn "\n"
  7. #define pi pair<int, int>
  8. #define fi first
  9. #define se second
  10. #define lb lower_bound
  11. #define ub upper_bound
  12. #define eb emplace_back
  13. #define pb push_back
  14. #define TASK " "
  15.  
  16. #define ms(a, x) memset(a, x, sizeof(a))
  17. #define all(a) a.begin(), a.end()
  18. #define All(a, n) a + 1, a + 1 + n
  19.  
  20. #define LOG 19
  21.  
  22. const int INF = 1e18;
  23. const int mod = 1e9+7;
  24. const int N = 2e5 + 5;
  25. int MOD = 998244353;
  26. int bit[200000];
  27.  
  28. struct node{
  29. int kc, u, hk;
  30. bool operator<(const node& other) const {
  31. return kc > other.kc;
  32. }
  33. };
  34.  
  35. struct edge{
  36. int u, v, w;
  37. friend bool operator < (edge a, edge b){
  38. return a.w < b.w;
  39. }
  40. };
  41.  
  42. void nhap(){
  43.  
  44. }
  45.  
  46. void solve(){
  47. int n;
  48. cin >> n;
  49. vector<pi> a(n + 1);
  50. for(int i = 1; i <= n; i++){
  51. cin >> a[i].fi;
  52. a[i].se = i;
  53. }
  54. sort(a.begin() + 1, a.end());
  55. int cnt0 = 0;
  56. for(int i = 1; i <= n; i++){
  57. if(a[i].fi == 0) cnt0++;
  58. }
  59. if(cnt0 == 1){
  60. cout << "NO" << nn;
  61. return;
  62. }
  63. cout << "YES" << nn;
  64. string ans(n, 'A');
  65. vector<int> mex(3, 0);
  66. for(int i = 1; i <= n; i++){
  67. int id = 0;
  68.  
  69. if(mex[1] < mex[id]){
  70. id = 1;
  71. }
  72. if(mex[2] < mex[id]){
  73. id = 2;
  74. }
  75. if(id == 0){
  76. ans[a[i].se - 1] = 'A';
  77. }
  78. else if(id == 1){
  79. ans[a[i].se - 1] = 'B';
  80. }
  81. else{
  82. ans[a[i].se - 1] = 'C';
  83. }
  84. if(a[i].fi == mex[id]){
  85. mex[id]++;
  86. }
  87. }
  88. cout << ans << nn;
  89. }
  90.  
  91. signed main(){
  92. ios_base::sync_with_stdio(0);
  93. cin.tie(0);
  94. cout.tie(0);
  95.  
  96. int t;
  97. cin >> t;
  98.  
  99. while(t--){
  100. solve();
  101. }
  102.  
  103. return 0;
  104. }
Success #stdin #stdout 0s 5312KB
stdin
5
6
1 0 0 1 2 1
4
0 0 0 0
3
0 2 2
4
6 7 6 7
5
0 0 0 1 2
stdout
YES
CABCCC
YES
ABCA
NO
YES
AAAA
YES
ABCAB