A8960 | Secret
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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,|Ui}|)$ . 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,|Ui}|$ 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.
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,|Ui}|$ 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.
输入格式
The input consists of a single line which contains two integers $n$ and $k$ ( $2<=k<=n<=10^{6}$ ) — the number of words in the secret and the number of the Keepers. The numbers are separated by a single space.
输出格式
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.
If there are multiple solutions, print any of them.
输入输出样例
输入 #1
11 3
输出 #1
3 1 2 1 1 2 3 2 2 3 1
输入 #2
5 2
输出 #2
-1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted