CF2259D.MEX Multiset
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a1,a2,…,an. There exist 3 initially empty multisets A,B,C, and for each index i (1≤i≤n), you may put ai into exactly one of A, B, or C.
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))∗. If so, output a construction that achieves this.
∗MEX(D) is defined as the smallest non-negative integer that is not present in the set D. For example, MEX([1,2,0,5])=3, and MEX([1,2,4,9])=0. The MEX of an empty set is 0.
给你一个数组 a1,a2,…,an。存在三个初始为空的多重集 A,B,C,对于每个下标 i(1≤i≤n),你可以将 ai 恰好放入 A、B 或 C 中的一个。
判断是否可能将所有元素分配到这三个多重集中,使得
MEX(A)+MEX(B)+MEX(C)≥2⋅max(MEX(A),MEX(B),MEX(C))
成立。若可行,请输出一种满足条件的分配方案。
∗ MEX(D) 定义为集合 D 中未出现的最小非负整数。例如,MEX([1,2,0,5])=3,而 MEX([1,2,4,9])=0。空集的 MEX 为 0。
输入格式
The first line of each input contains t (1≤t≤104) — the number of test cases.
The first line of each test case contains n (3≤n≤2⋅105) — the length of a.
The second line of each test case contains a1,a2,…,an (0≤ai≤109) — the array a.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每组输入的第一行包含 t(1≤t≤104)—— 测试用例的数量。
每个测试用例的第一行包含 n(3≤n≤2⋅105)—— 数组 a 的长度。
每个测试用例的第二行包含 a1,a2,…,an(0≤ai≤109)—— 数组 a。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
If a valid distribution of elements into the multisets exists, output YES. Otherwise, output NO.
If the answer is YES, output a string s of length n on a new line, such that si=A if the i-th element was put into the multiset A, si=B if the i-th element was put into the multiset B, and si=C if the i-th element was put into the multiset C.
You can output the answer in any case (upper or lower). For example, the strings YES, yes, yEs, and Yes will be recognized as positive responses, and the strings NO, no, No will be recognized as negative responses. Additionally, the strings AABCAAA, aabcaaa, and aaBcaaa will be recognized as the same answer.
If there are multiple possible outputs, output any.
如果存在一种将元素分配到多重集的合法方案,则输出 YES;否则输出 NO。
若答案为 YES,则在下一行输出一个长度为 n 的字符串 s,其中:若第 i 个元素被放入多重集 A,则 si=A;若被放入多重集 B,则 si=B;若被放入多重集 C,则 si=C。
答案大小写不限。例如,字符串 YES、yes、yEs 和 Yes 均被视为肯定回答;字符串 NO、no、No 均被视为否定回答。此外,字符串 AABCAAA、aabcaaa 和 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,1, B=0,1, C=2, meaning MEX(A)+MEX(B)+MEX(C)=4, and 2⋅max(MEX(A),MEX(B),MEX(C))=2⋅max(2,2,0)=4.
In the third test case, it can be shown that there are no valid distributions.
在第一个测试用例中,我们可以取 A={0,1,1},B={0,1},C={2},此时有 MEX(A)+MEX(B)+MEX(C)=4,且 2⋅max(MEX(A),MEX(B),MEX(C))=2⋅max(2,2,0)=4。
在第三个测试用例中,可以证明不存在合法的划分方案。
输入解题思路,AI测评打分。不知道怎么写?