QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100

#6449. 增量双重自由字符串

Statistics

如果一个字符串中没有两个相邻的字母相同,则称该字符串为“双重自由”(double free)字符串。

如果一个字符串满足以下条件,则称其为 $k$-增量($k$-incremental)字符串:对于区间 $[1, k]$ 内的所有值 $j$,恰好存在一个字符出现了 $j$ 次,且字符串的总长度为 $1+2+3+\dots+(k-1)+k$。例如,当 $k=3$ 时,一个 $3$-增量字符串应包含一个出现 1 次的字符、一个出现 2 次的字符和一个出现 3 次的字符,总长度为 6。

一个字符串如果同时满足上述两个条件,则称其为 $k$-增量双重自由字符串。现在考虑将所有满足条件的给定 $k$ 的小写字母字符串按字母顺序排列。请看以下示例:

$k = 2$: aba, aca, ada, ..., aya, aza, bab, bcb, bdb, ..., zxz, zyz $k = 3$: ababac, ababad, ..., ababay, ababaz, ababca, ..., zyzyzx

请问在所有 $k$-增量双重自由字符串按字母顺序排列的列表中,第 $n$ 个字符串是什么?

输入格式

每个输入包含一个测试用例。注意,程序可能会在不同的输入上多次运行。输入仅包含一行,包含两个整数 $k$ 和 $n$ ($1 \le k \le 26, 1 \le n \le 10^{18}$),表示要求按字母顺序排列的第 $n$ 个 $k$-增量双重自由字符串。

输出格式

输出按字母顺序排列的第 $n$ 个 $k$-增量双重自由字符串。如果不存在这样的字符串,则输出 $-1$。

样例

输入 1

2 650

输出 1

zyz

输入 2

2 651

输出 2

-1

输入 3

5 12345678901234

输出 3

yuzczuyuyuzuyci

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.