QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 256 MB 満点: 100 ハック可能 ✓

#12346. 平方词

統計

给定一个 $1$ 到 $n$ 的排列,请找出一个满足以下规则的方阵:

  1. 矩阵仅包含该排列中的数字;
  2. 给定的排列在矩阵的每一行中都作为连续子序列出现(从左到右读取);
  3. 给定的排列在矩阵的每一列中都作为连续子序列出现(从上到下读取);
  4. 矩阵的尺寸尽可能小。

输入格式

第一行输入一个正整数 $n \le 500$。 第二行输入 $n$ 个空格分隔的整数,即该排列本身。

输出格式

第一行输出一个整数 $m$,表示矩阵的尺寸。接下来的 $m$ 行应列出矩阵的 $m$ 行内容。每一行包含 $m$ 个空格分隔的整数,即对应行的数值。

尺寸 $m$ 应尽可能小。如果存在多种可能的答案,输出其中任意一个即可。

样例

输入 1

2
1 2

输出 1

3
1 2 1
2 1 2
1 2 1

说明

以下是样例中排列在矩阵中出现的位置:

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 0
No discussions in this category.

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.