QOJ.ac

QOJ

時間限制: 6.0 s 記憶體限制: 512 MB 總分: 100 可 Hack ✓

#12335. 结合度

统计

考虑定义在 $1$ 到 $n$ 上的二元运算 $\circ$: $$\circ : \{1, \dots, n\} \times \{1, \dots, n\} \to \{1, \dots, n\}.$$

我们定义其结合度(associativity degree)为满足以下结合律的三元组 $(i, j, k) \in \{1, \dots, n\}^3$ 的数量: $$i \circ (j \circ k) = (i \circ j) \circ k.$$

你的任务是,给定 $n$ 和 $k$,构造一个运算 $\circ$,使得其结合度恰好为 $k$。

输入格式

第一行包含两个整数 $n$ 和 $q$ ($1 \le n \le 64, 1 \le q \cdot n^2 \le 10^6$)。 接下来的 $q$ 行,每行包含一个整数 $k_i$ ($0 \le k_i \le n^3$)。 保证所有的 $k_i$ 互不相同。

输出格式

对于每个给定的 $k_i$,执行以下操作: 如果对于给定的 $n$,不存在结合度为 $k_i$ 的运算 $\circ$,则输出一行 “NO”。 否则,第一行输出 “YES”,随后输出 $n$ 行,每行包含 $n$ 个整数。第 $i$ 行的第 $j$ 个整数必须等于 $i \circ j$。

样例

输入 1

3 1
27

输出 1

YES
1 1 1
1 2 3
1 3 2

输入 2

1 2
0
1

输出 2

NO
YES
1

说明

第一个样例中的运算可以简洁地描述为 $i \circ j = 1 + ((i - 1) \cdot (j - 1)) \pmod 3$,它是完全满足结合律的。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#235EditorialOpen题解jiangly2025-12-13 00:24:03View

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 1
IDTypeStatusTitlePosted ByLast UpdatedActions
#1664General DiscussionOpen并不一定是一个正确的思路bunH2O2026-05-01 22:43:29View

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.