CF1102B.Array K-Coloring
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a consisting of n integer numbers.
You have to color this array in k colors in such a way that:
- Each element of the array should be colored in some color;
- For each i from 1 to k there should be at least one element colored in the i-th color in the array;
- For each i from 1 to k all elements colored in the i-th color should be distinct.
Obviously, such coloring might be impossible. In this case, print "NO". Otherwise print "YES" and any coloring (i.e. numbers c1,c2,…cn, where 1≤ci≤k and ci is the color of the i-th element of the given array) satisfying the conditions above. If there are multiple answers, you can print any.
给你一个包含 n 个整数的数组 a。
你需要将该数组用 k 种颜色进行染色,使得满足以下条件:
- 数组中的每个元素都必须被染上某种颜色;
- 对每个从 1 到 k 的 i,数组中至少有一个元素被染成第 i 种颜色;
- 对每个从 1 到 k 的 i,所有被染成第 i 种颜色的元素的值必须互不相同。
显然,这样的染色方案可能并不存在。此时,请输出 "NO"。否则,请输出 "YES" 以及任意一种满足上述条件的染色方案(即输出数字序列 c1,c2,…,cn,其中 1≤ci≤k,且 ci 表示给定数组中第 i 个元素所染的颜色)。若存在多种答案,输出任意一种即可。
输入格式
The first line of the input contains two integers n and k (1≤k≤n≤5000) — the length of the array a and the number of colors, respectively.
The second line of the input contains n integers a1,a2,…,an (1≤ai≤5000) — elements of the array a.
输入的第一行包含两个整数 n 和 k(1≤k≤n≤5000)——分别表示数组 a 的长度和颜色种类数。
输入的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤5000)——数组 a 的元素。
输出格式
If there is no answer, print "NO". Otherwise print "YES" and any coloring (i.e. numbers c1,c2,…cn, where 1≤ci≤k and ci is the color of the i-th element of the given array) satisfying the conditions described in the problem statement. If there are multiple answers, you can print any.
如果没有答案,输出 “NO”。否则输出 “YES” 以及任意一种满足题目描述条件的染色方案(即输出数字 c1,c2,…,cn,其中 1≤ci≤k,且 ci 表示给定数组中第 i 个元素的颜色)。如果存在多个答案,输出任意一个即可。
输入输出样例
输入#1
4 2 1 2 2 3
输出#1
YES 1 1 2 2
输入#2
5 2 3 2 1 2 3
输出#2
YES 2 1 1 2 1
输入#3
5 2 2 1 1 2 1
输出#3
NO
说明/提示
In the first example the answer 2 1 2 1 is also acceptable.
In the second example the answer 1 1 1 2 2 is also acceptable.
There exist other acceptable answers for both examples.
在第一个例子中,答案 2 1 2 1 同样可接受。
在第二个例子中,答案 1 1 1 2 2 同样可接受。
这两个例子均存在其他可接受的答案。
输入解题思路,AI测评打分。不知道怎么写?