QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 32 MB Puntuación total: 100

#12976. 无重复子串的序列

Estadísticas

我们考虑字母序列。如果一个序列 $x_1, x_2, \dots, x_n$ 中存在两个相邻的相同子序列,即存在 $i$ 和 $j$ ($1 \le i < j \le \frac{n+i+1}{2}$) 使得 $x_i=x_j, x_{i+1}=x_{j+1}, \dots, x_{j-1}=x_{2j-i-1}$,则称该序列包含“口吃”(stammer)。

我们关注的是由最少数量的不同字母构成的、不包含“口吃”的 $n$ 元序列。

样例

对于 $n=3$,使用两个字母(例如 $a$ 和 $b$)就足够了。由这两个字母构成的、不包含“口吃”的 3 元序列恰好有两个:$aba$ 和 $bab$。对于 $n=5$,我们需要三个不同的字母。例如,$abcab$ 就是一个不包含“口吃”的三字母序列。而在序列 $babab$ 中,存在两个“口吃”:$ba$ 和 $ab$。

任务

编写一个程序:

  • 读取序列长度 $n$;
  • 计算出一个由最少数量的不同字母构成的、不包含“口吃”的 $n$ 元序列;
  • 输出结果。

输入格式

标准输入的第一行包含一个正整数 $n$,$1 \le n \le 10,000,000$。

输出格式

程序应输出到标准输出。第一行应包含一个正整数 $k$,表示构成不包含“口吃”的 $n$ 元序列所需的最少不同字母数量。

第二行应输出计算出的不包含“口吃”的序列,作为一个由 $n$ 个小写英文字母组成的单词,且仅使用从 $a$ 开始的前 $k$ 个字母。如果存在多个这样的序列,输出其中任意一个即可。

样例

样例输入 1

5

样例输出 1

3
abcab

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.