CF2259D.MEX Multiset

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array a1,a2,…,ana_1, a_2, \ldots, a_n. There exist 33 initially empty multisets A,B,CA, B, C, and for each index ii (1≤i≤n1 \leq i \leq n), you may put aia_i into exactly one of AA, BB, or CC.

Determine whether it is possible to put the elements into the multisets such that MEX⁡(A)+MEX⁡(B)+MEX⁡(C)≥2⋅max⁡(MEX⁡(A),MEX⁡(B),MEX⁡(C))\operatorname{MEX}(A) + \operatorname{MEX}(B) + \operatorname{MEX}(C) \geq 2 \cdot \max(\operatorname{MEX}(A), \operatorname{MEX}(B), \operatorname{MEX}(C))∗^{\text{∗}}. If so, output a construction that achieves this.

∗^{\text{∗}}MEX⁡(D)\operatorname{MEX}(D) is defined as the smallest non-negative integer that is not present in the set DD. For example, MEX⁡([1,2,0,5])=3\operatorname{MEX}([1, 2, 0, 5]) = 3, and MEX⁡([1,2,4,9])=0\operatorname{MEX}([1, 2, 4, 9]) = 0. The MEX⁡\operatorname{MEX} of an empty set is 00.

给你一个数组 a1,a2,…,ana_1, a_2, \ldots, a_n。存在三个初始为空的多重集 A,B,CA, B, C,对于每个下标 ii(1≤i≤n1 \leq i \leq n),你可以将 aia_i 恰好放入 AA、BB 或 CC 中的一个。

判断是否可能将所有元素分配到这三个多重集中,使得

MEX⁡(A)+MEX⁡(B)+MEX⁡(C)≥2⋅max⁡(MEX⁡(A),MEX⁡(B),MEX⁡(C))\operatorname{MEX}(A) + \operatorname{MEX}(B) + \operatorname{MEX}(C) \geq 2 \cdot \max(\operatorname{MEX}(A), \operatorname{MEX}(B), \operatorname{MEX}(C))

成立。若可行,请输出一种满足条件的分配方案。

∗^{\text{∗}} MEX⁡(D)\operatorname{MEX}(D) 定义为集合 DD 中未出现的最小非负整数。例如,MEX⁡([1,2,0,5])=3\operatorname{MEX}([1, 2, 0, 5]) = 3,而 MEX⁡([1,2,4,9])=0\operatorname{MEX}([1, 2, 4, 9]) = 0。空集的 MEX⁡\operatorname{MEX} 为 00。

输入格式

The first line of each input contains tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains nn (3≤n≤2⋅1053 \leq n \leq 2 \cdot 10^5) — the length of aa.

The second line of each test case contains a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1090 \leq a_i \leq 10^9) — the array aa.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

每组输入的第一行包含 tt(1≤t≤1041 \leq t \leq 10^4)—— 测试用例的数量。

每个测试用例的第一行包含 nn(3≤n≤2⋅1053 \leq n \leq 2 \cdot 10^5)—— 数组 aa 的长度。

每个测试用例的第二行包含 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤1090 \leq a_i \leq 10^9)—— 数组 aa。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

If a valid distribution of elements into the multisets exists, output YES\texttt{YES}. Otherwise, output NO\texttt{NO}.

If the answer is YES\texttt{YES}, output a string ss of length nn on a new line, such that si=As_i = \texttt{A} if the ii-th element was put into the multiset AA, si=Bs_i = \texttt{B} if the ii-th element was put into the multiset BB, and si=Cs_i = \texttt{C} if the ii-th element was put into the multiset CC.

You can output the answer in any case (upper or lower). For example, the strings YES\texttt{YES}, yes\texttt{yes}, yEs\texttt{yEs}, and Yes\texttt{Yes} will be recognized as positive responses, and the strings NO\texttt{NO}, no\texttt{no}, No\texttt{No} will be recognized as negative responses. Additionally, the strings AABCAAA\texttt{AABCAAA}, aabcaaa\texttt{aabcaaa}, and aaBcaaa\texttt{aaBcaaa} will be recognized as the same answer.

If there are multiple possible outputs, output any.

如果存在一种将元素分配到多重集的合法方案,则输出 YES\texttt{YES};否则输出 NO\texttt{NO}。

若答案为 YES\texttt{YES},则在下一行输出一个长度为 nn 的字符串 ss,其中:若第 ii 个元素被放入多重集 AA,则 si=As_i = \texttt{A};若被放入多重集 BB,则 si=Bs_i = \texttt{B};若被放入多重集 CC,则 si=Cs_i = \texttt{C}。

答案大小写不限。例如,字符串 YES\texttt{YES}、yes\texttt{yes}、yEs\texttt{yEs} 和 Yes\texttt{Yes} 均被视为肯定回答;字符串 NO\texttt{NO}、no\texttt{no}、No\texttt{No} 均被视为否定回答。此外,字符串 AABCAAA\texttt{AABCAAA}、aabcaaa\texttt{aabcaaa} 和 aaBcaaa\texttt{aaBcaaa} 将被视为同一答案。

若存在多种可能的输出,输出任意一种即可。

输入输出样例

  • 输入#1

    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

    输出#1

    YES
    ABABCA
    YES
    ABAC
    NO
    YES
    AAAB
    YES
    ABCAB

说明/提示

In the first test case, we can have A=0,1,1A = {0, 1, 1}, B=0,1B = {0, 1}, C=2C = {2}, meaning MEX⁡(A)+MEX⁡(B)+MEX⁡(C)=4\operatorname{MEX}(A) + \operatorname{MEX}(B) + \operatorname{MEX}(C) = 4, and 2⋅max⁡(MEX⁡(A),MEX⁡(B),MEX⁡(C))=2⋅max⁡(2,2,0)=42 \cdot \max(\operatorname{MEX}(A), \operatorname{MEX}(B), \operatorname{MEX}(C)) = 2 \cdot \max(2, 2, 0) = 4.

In the third test case, it can be shown that there are no valid distributions.

在第一个测试用例中,我们可以取 A={0,1,1}A = \{0, 1, 1\},B={0,1}B = \{0, 1\},C={2}C = \{2\},此时有 MEX⁡(A)+MEX⁡(B)+MEX⁡(C)=4\operatorname{MEX}(A) + \operatorname{MEX}(B) + \operatorname{MEX}(C) = 4,且 2⋅max⁡(MEX⁡(A),MEX⁡(B),MEX⁡(C))=2⋅max⁡(2,2,0)=42 \cdot \max(\operatorname{MEX}(A), \operatorname{MEX}(B), \operatorname{MEX}(C)) = 2 \cdot \max(2, 2, 0) = 4。

在第三个测试用例中,可以证明不存在合法的划分方案。

输入解题思路,AI测评打分。不知道怎么写?

首页