【CodeForces - 1051C 】Vasya and Multisets (模拟)

版权声明:欢迎学习我的博客,希望ACM的发展越来越好~ https://blog.csdn.net/qq_41289920/article/details/83587982

题干:

Vasya has a multiset ss consisting of nn integer numbers. Vasya calls some number xxnice 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 aa and 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 ss goes to multiset aa and 'B' if if the ii-th element of multiset ss goes to multiset bb. Elements are numbered from 11to nn in the order they are given in the input.

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

扫描二维码关注公众号,回复: 3911078 查看本文章

Examples

Input

4
3 5 7 1

Output

YES
BABA

Input

3
3 5 1

Output

NO

解题报告:

   很简单的题意模拟题啊。。。搞WA了好几发、、还是码力不足啊、、写的好复杂、、

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
int bk[1005],qq[1005];
char opa[1005];
int a[1005],cnt;
int main()
{
	int n;
	cin>>n;
	for(int i = 1; i<=n; i++) {
		scanf("%d",a+i);
		bk[a[i]]++;
	}
	bool flag = 0;
	for(int i = 1; i<=n; i++) {
		if(bk[a[i]] == 2) opa[i]='A';
		else if(bk[a[i]] == 1) {
			cnt++;
			if(flag) opa[i]='A';
			else opa[i]='B';
			flag=!flag;
		}
	}
	if(cnt % 2 == 0) {
		puts("YES");
		for(int i = 1; i<=n; i++) {
			if(opa[i] !=0) putchar(opa[i]);
			else putchar('A');
		}
		return 0 ;
	}
	bool ok=0;
	for(int i = 1; i<=n; i++) {
		if(opa[i] == 0) {
			if(bk[a[i]] > 2) {
				if(flag) {
					opa[i] = 'A';
					for(int j = i+1; j<=n; j++) {
						if(a[j] == a[i]) opa[j] = 'B';
					}
				}
				else {
					opa[i] = 'B';
					for(int j = i+1; j<=n; j++) {
						if(a[j] == a[i]) opa[j] = 'A';
					}
				}
				ok=1;break;
			}
		}
	}
	if(ok==0) {
		puts("NO");return 0 ;
	}
	puts("YES");
	for(int i = 1; i<=n; i++) {
		if(opa[i]!=0) putchar(opa[i]);
		else putchar('A');
	}
	return 0 ;
 }
/*
12
1 2 3 4 5 5 6 6 6 7 9 11
YES
ABABAABAAABA
7
1 2 3 4 4 4 4
YES
ABABAAA
*/

猜你喜欢

转载自blog.csdn.net/qq_41289920/article/details/83587982