Technocup 2022 - Elimination Round 1
F
Defender of Childhood Dreams
Codeforces
2500
原题
← EG →
翻译中…

Even if you just leave them be, they will fall to pieces all by themselves. So, someone has to protect them, right?

翻译中…

You find yourself playing with Teucer again in the city of Liyue. As you take the eccentric little kid around, you notice something interesting about the structure of the city.

翻译中…

Liyue can be represented as a directed graph containing $n$ nodes. Nodes are labeled from $1$ to $n$. There is a directed edge from node $a$ to node $b$ if and only if $a \lt b$.

翻译中…

A path between nodes $a$ and $b$ is defined as a sequence of edges such that you can start at $a$, travel along all of these edges in the corresponding direction, and end at $b$. The length of a path is defined by the number of edges. A rainbow path of length $x$ is defined as a path in the graph such that there exists at least 2 distinct colors among the set of $x$ edges.

翻译中…

Teucer's favorite number is $k$. You are curious about the following scenario: If you were to label each edge with a color, what is the minimum number of colors needed to ensure that all paths of length $k$ or longer are rainbow paths?

翻译中…

Teucer wants to surprise his older brother with a map of Liyue. He also wants to know a valid coloring of edges that uses the minimum number of colors. Please help him with this task!

翻译中…

Input

翻译中…

The only line of input contains two integers $n$ and $k$ ($2 \leq k \lt n \leq 1000$).

翻译中…

Output

翻译中…

On the first line, output $c$, the minimum colors you need to satisfy the above requirements.

翻译中…

On the second line, print a valid edge coloring as an array of $\frac{n(n-1)}{2}$ integers ranging from $1$ to $c$. Exactly $c$ distinct colors should exist in the construction. Print the edges in increasing order by the start node first, then by the second node.

翻译中…

For example, if $n=4$, the edge colors will correspond to this order of edges: ($1$, $2$), ($1$, $3$), ($1$, $4$), ($2$, $3$), ($2$, $4$), ($3$, $4$)

翻译中…

Note

翻译中…

The corresponding construction for the first test case looks like this:

翻译中…

image

翻译中…

It is impossible to satisfy the constraints with less than $2$ colors.

翻译中…

The corresponding construction for the second test case looks like this:

翻译中…

image

翻译中…

One can show there exists no construction using less than $3$ colors.

翻译中…

样例

Input #1
5 3
Output #1
2
1 2 2 2 2 2 2 1 1 1
InputCopy OutputCopy
Input #2
5 2
Output #2
3
3 2 2 1 2 2 1 3 1 1
InputCopy OutputCopy
Input #3
8 7
Output #3
2
2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
InputCopy OutputCopy
Input #4
3 2
Output #4
2
1 2 2
InputCopy OutputCopy
题目信息
题号
1583F
时间限制
3 s
内存限制
512 MB
标签
位运算
构造
分治

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。