CF1102B.Array K-Coloring

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array aa consisting of nn integer numbers.

You have to color this array in kk colors in such a way that:

  • Each element of the array should be colored in some color;
  • For each ii from 11 to kk there should be at least one element colored in the ii-th color in the array;
  • For each ii from 11 to kk all elements colored in the ii-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,…cnc_1, c_2, \dots c_n, where 1≤ci≤k1 \le c_i \le k and cic_i is the color of the ii-th element of the given array) satisfying the conditions above. If there are multiple answers, you can print any.

给你一个包含 nn 个整数的数组 aa。

你需要将该数组用 kk 种颜色进行染色,使得满足以下条件:

  • 数组中的每个元素都必须被染上某种颜色;
  • 对每个从 11 到 kk 的 ii,数组中至少有一个元素被染成第 ii 种颜色;
  • 对每个从 11 到 kk 的 ii,所有被染成第 ii 种颜色的元素的值必须互不相同。

显然,这样的染色方案可能并不存在。此时,请输出 "NO"。否则,请输出 "YES" 以及任意一种满足上述条件的染色方案(即输出数字序列 c1,c2,…,cnc_1, c_2, \dots, c_n,其中 1≤ci≤k1 \le c_i \le k,且 cic_i 表示给定数组中第 ii 个元素所染的颜色)。若存在多种答案,输出任意一种即可。

输入格式

The first line of the input contains two integers nn and kk (1≤k≤n≤50001 \le k \le n \le 5000) — the length of the array aa and the number of colors, respectively.

The second line of the input contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤50001 \le a_i \le 5000) — elements of the array aa.

输入的第一行包含两个整数 nn 和 kk(1≤k≤n≤50001 \le k \le n \le 5000)——分别表示数组 aa 的长度和颜色种类数。

输入的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤50001 \le a_i \le 5000)——数组 aa 的元素。

输出格式

If there is no answer, print "NO". Otherwise print "YES" and any coloring (i.e. numbers c1,c2,…cnc_1, c_2, \dots c_n, where 1≤ci≤k1 \le c_i \le k and cic_i is the color of the ii-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,…,cnc_1, c_2, \dots, c_n,其中 1≤ci≤k1 \le c_i \le k,且 cic_i 表示给定数组中第 ii 个元素的颜色)。如果存在多个答案,输出任意一个即可。

输入输出样例

  • 输入#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 12~ 1~ 2~ 1 is also acceptable.

In the second example the answer 1 1 1 2 21~ 1~ 1~ 2~ 2 is also acceptable.

There exist other acceptable answers for both examples.

在第一个例子中,答案 2 1 2 12~ 1~ 2~ 1 同样可接受。

在第二个例子中,答案 1 1 1 2 21~ 1~ 1~ 2~ 2 同样可接受。

这两个例子均存在其他可接受的答案。

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

首页