丸紅プログラミングコンテスト2024(AtCoder Regular Contest 183)
A
Median of Good Sequences
AtCoder
⌀ 539
原题
←B →
翻译中…

Problem Statement

翻译中…

You are given positive integers $N$ and $K$.

翻译中…

An integer sequence of length $NK$ where each integer from $1$ to $N$ appears exactly $K$ times is called a good integer sequence.

翻译中…

Let $S$ be the number of good integer sequences. Find the $\operatorname{floor}((S+1)/2)$-th good integer sequence in lexicographical order. Here, $\operatorname{floor}(x)$ represents the largest integer not exceeding $x$.

翻译中…

What is lexicographical order for sequences? A sequence $S = (S_1,S_2,\ldots,S_{|S|})$ is lexicographically smaller than a sequence $T = (T_1,T_2,\ldots,T_{|T|})$ if either 1. or 2. below holds. Here, $|S|$ and $|T|$ represent the lengths of $S$ and $T$, respectively. $|S| \lt |T|$ and $(S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|})$. There exists an integer $1 \leq i \leq \min\lbrace |S|, |T| \rbrace$ such that both of the following hold: $(S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1})$ $S_i$ is (numerically) smaller than $T_i$.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 500$
  • $1 \leq K \leq 500$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N K

翻译中…

Output

翻译中…

Print the desired integer sequence, with elements separated by spaces.

翻译中…

样例

Input #1
2 2
Output #1
1 2 2 1
There are six good integer sequences: - $(1,1,2,2)$ - $(1,2,1,2)$ - $(1,2,2,1)$ - $(2,1,1,2)$ - $(2,1,2,1)$ - $(2,2,1,1)$ Therefore, the answer is the 3rd sequence in lexicographical order, $(1,2,2,1)$.
Input #2
1 5
Output #2
1 1 1 1 1
Input #3
6 1
Output #3
3 6 5 4 2 1
Input #4
3 3
Output #4
2 2 2 1 3 3 3 1 1
题目信息
题号
arc183_a
时间限制
2 s
内存限制
1024 MB

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