#P16147. [ICPC 2017 NAIPC] Incremental Double Free Strings

[ICPC 2017 NAIPC] Incremental Double Free Strings

题目描述

A string is called double free if no two adjacent letters are the same.

A string is called kk-incremental if for all values of jj in the range [1,k][1, k], there exists exactly one character with jj occurrences, and the string’s length is 1+2+3++(k1)+k1 + 2 + 3 + \ldots + (k - 1) + k. For example, if k=3k = 3, then a 3-incremental string should have one character appear once, another twice, another three times, in any order, for a total string length of 66.

A string is both kk-incremental and double free if it meets both these criteria. Now consider examining all such strings of lowercase letters for a given kk in alphabetical order. Consider the following examples.

k=2k = 2: aba, aca, ada, \ldots, aya, aza, bab, bcb, bdb, \ldots, zxz, zyz

k=3k = 3: ababac, ababad, \ldots, ababay, ababaz, ababca, \ldots, zyzyzx

What is the nthn^{\text{th}} string in an alphabetized list of all kk-incremental, double free strings?

输入格式

Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. There will be exactly one line of input. It will contain two integers, kk and nn (1k26,1n10181 \leq k \leq 26, 1 \leq n \leq 10^{18}), which is asking for the nthn^{\text{th}} string in the alphabetically sorted list of all kk-incremental, double free strings.

输出格式

Output the nthn^{\text{th}} kk-incremental, double free string in the alphabetized list. If no such string exists, output 1-1.

2 650
zyz
2 651
-1
5 12345678901234
yuzczuyuyuzuyci