codeforces1051C—— Vasya and Multisets【思维,模拟】

C. Vasya and Multisets

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vasya has a multiset ss consisting of nn integer numbers. Vasya calls some number xx nice if it appears in the multiset exactly once. For example, multiset {1,1,2,3,3,3,4}{1,1,2,3,3,3,4} contains nice numbers 22 and 44.

Vasya wants to split multiset ss into two multisets aa and bb (one of which may be empty) in such a way that the quantity of nice numbers in multiset aa would be the same as the quantity of nice numbers in multiset bb (the quantity of numbers to appear exactly once in multiset aaand the quantity of numbers to appear exactly once in multiset bb).

Input

The first line contains a single integer n (2≤n≤100)n (2≤n≤100).

The second line contains nn integers s1,s2,…sn (1≤si≤100)s1,s2,…sn (1≤si≤100) — the multiset ss.

Output

If there exists no split of ss to satisfy the given requirements, then print "NO" in the first line.

Otherwise print "YES" in the first line.

The second line should contain a string, consisting of nn characters. ii-th character should be equal to 'A' if the ii-th element of multiset ssgoes to multiset aa and 'B' if if the ii-th element of multiset ss goes to multiset bb. Elements are numbered from 11 to nn in the order they are given in the input.

If there exist multiple solutions, then print any of them.

Examples

input

Copy

4
3 5 7 1

output

Copy

YES
BABA

input

Copy

3
3 5 1

output

Copy

NO

我们定义一个数在一个几何里面只出现一次我们把他叫做“好数”,给定一组数,我们把他们分为A,B两组,保证两组的好数的数量相同。

题目大致思路:我们先把出现两次的数字都放到统一个集合中,相当于他们没有出现过,然后在考虑出现一次的数字,如果出现一次的数字是偶数个则能分,如果是奇数则不能分。然后在考虑出现次数>=3的数字,我们他们一次交替放在一个集合中。

#include <bits/stdc++.h>
using namespace std;

const int MAXN = 10010;
int a[MAXN];
char ans[MAXN];
map<int, int> cnt;

int main(){
	int n;
	while(~scanf("%d",&n)){
		for(int i = 1; i <= n; i++){
			scanf("%d",&a[i]);
			cnt[a[i]]++;
		}
		int sum1 = 0,sum3 = 0;
		for(int i = 1; i <= 100; i++){
			if(cnt[i] == 1) sum1++;
			else if(cnt[i] >= 3) sum3++;
		}
		for(int i = 1; i <= n; i++){
			if(cnt[a[i]] == 2) ans[i] = 'A';
		}
		if(sum1 % 2 == 0){
			puts("YES");
			int flag = 0;
			for(int i = 1; i <= n; i++){
				if(cnt[a[i]] == 1){
					ans[i] = 'A' + flag;
					flag ^= 1;
				}else ans[i] = 'A';
			}
			for(int i = 1; i <= n; i++) printf("%c",ans[i]);
			printf("\n");
			continue;
		}
		if(sum3 == 0) { puts("NO"); continue; }
		puts("YES");
		int flag = 0;
		for(int i = 1; i <= n; i++){
			if(cnt[a[i]] >= 3){
				ans[i] = 'B' - flag;
				flag = 1;
			}
		}
		flag = 0;
		for(int i = 1; i <= n; i++){
			if(cnt[a[i]] == 1){
				ans[i] = 'A' + flag;
				flag ^= 1;
			}
		}
		for(int i = 1; i <= n; i++) printf("%c",ans[i]);
		printf("\n");
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值