CF271C.Secret

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The Greatest Secret Ever consists of n words, indexed by positive integers from 1 to n. The secret needs dividing between k Keepers (let's index them by positive integers from 1 to k), the i-th Keeper gets a non-empty set of words with numbers from the set U__i = (u__i, 1, u__i, 2, ..., u__i, |U__i|). Here and below we'll presuppose that the set elements are written in the increasing order.

We'll say that the secret is safe if the following conditions are hold:

  • for any two indexes i, j (1 ≤ i < j ≤ k) the intersection of sets U__i and U__j is an empty set;
  • the union of sets _U_1, _U_2, ..., U__k is set (1, 2, ..., n);
  • in each set U__i, its elements u__i, 1, u__i, 2, ..., u__i, |U__i| do not form an arithmetic progression (in particular, |U__i| ≥ 3 should hold).

Let us remind you that the elements of set (_u_1, _u_2, ..., u__s) form an arithmetic progression if there is such number d, that for all i (1 ≤ i < s) fulfills u__i + d = u__i + 1. For example, the elements of sets (5), (1, 10) and (1, 5, 9) form arithmetic progressions and the elements of sets (1, 2, 4) and (3, 6, 8) don't.

Your task is to find any partition of the set of words into subsets _U_1, _U_2, ..., U__k so that the secret is safe. Otherwise indicate that there's no such partition.

《史上最伟大的秘密》由 nn 个单词组成,编号为从 11 到 nn 的正整数。该秘密需分配给 kk 位守护者(我们用从 11 到 kk 的正整数为其编号),其中第 ii 位守护者获得一个非空的单词集合,其编号构成集合 Ui=(ui,1, ui,2, …, ui,∣Ui∣)U_i = (u_{i,1},\, u_{i,2},\, \dots,\, u_{i,|U_i|})。此处及后文均默认集合中的元素按递增顺序排列。

我们称该秘密是安全的,当且仅当下列条件全部满足:

  • 对任意两个下标 i, ji,\,j(满足 1≤i<j≤k1 \le i < j \le k),集合 UiU_i 与 UjU_j 的交集为空集;
  • 集合 U1, U2, …, UkU_1,\, U_2,\, \dots,\, U_k 的并集等于集合 (1, 2, …, n)(1,\,2,\,\dots,\,n);
  • 在每个集合 UiU_i 中,其元素 ui,1, ui,2, …, ui,∣Ui∣u_{i,1},\, u_{i,2},\, \dots,\, u_{i,|U_i|} 不构成等差数列(特别地,必须有 ∣Ui∣≥3|U_i| \ge 3)。

我们提醒您:集合 (u1, u2, …, us)(u_1,\, u_2,\, \dots,\, u_s) 的元素构成等差数列,当且仅当存在某个数 dd,使得对所有 ii(满足 1≤i<s1 \le i < s)都有 ui+d=ui+1u_i + d = u_{i+1}。例如,集合 (5)(5)、(1, 10)(1,\,10) 和 (1, 5, 9)(1,\,5,\,9) 的元素构成等差数列;而集合 (1, 2, 4)(1,\,2,\,4) 和 (3, 6, 8)(3,\,6,\,8) 的元素则不构成等差数列。

您的任务是:找出一种将单词集合划分为子集 U1, U2, …, UkU_1,\, U_2,\, \dots,\, U_k 的方案,使得该秘密是安全的;若不存在这样的划分,则指出无解。

输入格式

The input consists of a single line which contains two integers n and k (2 ≤ k ≤ n ≤ 106) — the number of words in the secret and the number of the Keepers. The numbers are separated by a single space.

输入包含一行,其中包含两个整数 nn 和 kk(2 ≤ k ≤ n ≤ 1062 \leq k \leq n \leq 10^6)——分别表示密语中的单词数量和守护者的数量。这两个数字之间用一个空格分隔。

输出格式

If there is no way to keep the secret safe, print a single integer "-1" (without the quotes). Otherwise, print n integers, the i-th of them representing the number of the Keeper who's got the i-th word of the secret.

If there are multiple solutions, print any of them.

如果无法保证秘密的安全,请输出单个整数 “-1”(不带引号)。否则,输出 n 个整数,其中第 i 个整数表示持有秘密第 i 个单词的守护者编号。

若存在多个解,输出任意一个即可。

输入输出样例

  • 输入#1

    11 3

    输出#1

    3 1 2 1 1 2 3 2 2 3 1
  • 输入#2

    5 2

    输出#2

    -1

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

首页