第 473 场 AtCoder Beginner Contest
D
Coefficient Stair
AtCoder
⌀ 838
原题
← BG →

Coefficient StairAI (CI翻译)

Problem Statement

Output all length-$N$ sequences $A=(A _ 1,A _ 2,\ldots,A _ N)$ consisting of non-negative integers that satisfy $\displaystyle\sum _ {i=1} ^ Ni\times A _ i=K$, in lexicographic order from smallest to largest.

Here, you will only receive inputs such that the number of sequences satisfying the condition is at most $3\times10 ^ 5$.

What is lexicographic order for sequences? A sequence $S = (S_1,S_2,\ldots,S_{|S|})$ is said to be lexicographically smaller than a sequence $T = (T_1,T_2,\ldots,T_{|T|})$ if either 1. or 2. below holds. Here, $|S|$ and $|T|$ denote 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\le N\le 10$
  • $1\le K\le 2\times10 ^ 5$
  • The number of sequences satisfying the condition is at most $3\times10 ^ 5$.
  • All input values are integers.

Input

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

N K

Output

Let $q$ be the number of sequences of non-negative integers satisfying the condition; output them over $q$ lines. Each line should contain the elements of a sequence of non-negative integers satisfying the condition, in order, separated by spaces. For every sequence, all sequences outputed before it must be lexicographically smaller than it.

{"titleZh":"系数阶梯","bodyZh":"## 题目描述\n\n按从小到大的字典序,输出所有满足 $\displaystyle\\sum _ {i=1} ^ Ni\\times A _ i=K$ 的长度为 $N$ 的非负整数序列 $A=(A _ 1,A _ 2,\\ldots,A _ N)$。\n\n保证输入满足条件的序列数量不超过 $3\\times10 ^ 5$。\n\n序列的字典序是什么?如果以下 1. 或 2. 中任一条件成立,则称序列 $S = (S_1,S_2,\\ldots,S_{|S|})$ 的字典序小于序列 $T = (T_1,T_2,\\ldots,T_{|T|})$。这里,$|S|$ 和 $|T|$ 分别表示 $S$ 和 $T$ 的长度。\n\n1. $|S| \\lt |T|$,且 $(S_1,S_2,\\ldots,S_{|S|}) = (T_1,T_2,\\ldots,T_{|S|})$。\n2. 存在整数 $1 \\leq i \\leq \\min\\lbrace |S|, |T| \\rbrace$,使得以下两项均成立:$(S_1,S_2,\\ldots,S_{i-1}) = (T_1,T_2,\\ldots,T_{i-1})$;$S_i$ 的数值小于 $T_i$。\n\n## 约束条件\n\n- $1\\le N\\le 10$\n- $1\\le K\\le 2\\times10 ^ 5$\n- 满足条件的序列数量不超过 $3\\times10 ^ 5$。\n- 所有输入值均为整数。\n\n## 输入格式\n\n输入从标准输入中按以下格式给出:\n\n\nN K\n\n\n## 输出格式\n\n设满足条件的非负整数序列数量为 $q$,请输出 $q$ 行。每行包含一个满足条件的非负整数序列,各元素以空格分隔,并按顺序输出。对于每个序列,所有输出在它之前的序列都必须比它的字典序小。"}AI (CI翻译)

样例

Input #1
3 8
Output #1
0 1 2
0 4 0
1 2 1
2 0 2
2 3 0
3 1 1
4 2 0
5 0 1
6 1 0
8 0 0
For example, for the sequence $(0,1,2)$ we have $0\times1+1\times2+2\times3=0+2+6=8$, so it satisfies the condition. There is no sequence satisfying the condition that is lexicographically smaller than this one, so output `0 1 2` on the first line. Including $(0,1,2)$, ten sequences satisfy the condition. Output these in lexicographic order from smallest to largest.
Input #2
1 200000
Output #2
200000
Input #3
8 9
Output #3
0 0 0 1 1 0 0 0
0 0 1 0 0 1 0 0
0 0 3 0 0 0 0 0
0 1 0 0 0 0 1 0
0 1 1 1 0 0 0 0
0 2 0 0 1 0 0 0
0 3 1 0 0 0 0 0
1 0 0 0 0 0 0 1
1 0 0 2 0 0 0 0
1 0 1 0 1 0 0 0
1 1 0 0 0 1 0 0
1 1 2 0 0 0 0 0
1 2 0 1 0 0 0 0
1 4 0 0 0 0 0 0
2 0 0 0 0 0 1 0
2 0 1 1 0 0 0 0
2 1 0 0 1 0 0 0
2 2 1 0 0 0 0 0
3 0 0 0 0 1 0 0
3 0 2 0 0 0 0 0
3 1 0 1 0 0 0 0
3 3 0 0 0 0 0 0
4 0 0 0 1 0 0 0
4 1 1 0 0 0 0 0
5 0 0 1 0 0 0 0
5 2 0 0 0 0 0 0
6 0 1 0 0 0 0 0
7 1 0 0 0 0 0 0
9 0 0 0 0 0 0 0
题目信息
题号
abc473_d
时间限制
2 s
内存限制
1024 MB

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