Problem:
Score : 400 points

Problem Statement

A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:

In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.

For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.

You are given a positive integer K. Find the K-th smallest lunlun number.

Constraints

1 \leq K \leq 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

K

Output

Print the answer.

Sample Input 1

15

Sample Output 1

23

We will list the 15 smallest lunlun numbers in ascending order:

1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
21,
22,
23.

Thus, the answer is 23.

Sample Input 2

1

Sample Output 2

1

Sample Input 3

13

Sample Output 3

21

Sample Input 4

100000

Sample Output 4

3234566667

Note that the answer may not fit into the 32-bit signed integer type.

Solution in C# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iK = int.Parse(sS[0]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            List<long>   lstTbl = new List<long>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23, 32, 33, 34, 43, 44, 45, 54, 55, 56, 65, 66, 67, 76, 77, 78, 87, 88, 89, 98, 99, };
            List<string> lst2Kt = new List<string>() { "00", "01", "10", "11", "12", "21", "22", "23", "32", "33", "34", "43", "44", "45", "54", "55", "56", "65", "66", "67", "76", "77", "78", "87", "88", "89", "98", "99", };
            List<long> lstNxt = new List<long>() { };                                           // 新しく生成された値
            List<long> lstBak = new List<long>() { };
            for (int p = 2; p < lst2Kt.Count; p++) { lstBak.Add(long.Parse(lst2Kt[p])); }       // 元の値
            for (int i = 3; i < 11; i++)                                                        // 生成桁
            {
                for (int k = 1; k <= 9; k++)                                                    // 前に付加する値
                {
                    for (int p = 0; p < lstBak.Count; p++)
                    {
                        if (Math.Abs(int.Parse(lstBak[p].ToString().Substring(0, 1)) - k) < 2)
                        {
                            lstNxt.Add(long.Parse(k.ToString() + lstBak[p].ToString()));        // 前に付加した新しい値
                        }
                    }
                }
                for (int k = 0; k <= 9; k++)                                                    // 後に付加する値
                {
                    for (int p = 0; p < lstBak.Count; p++)
                    {
                        if (Math.Abs((lstBak[p] % 10) - k) < 2)
                        {
                            lstNxt.Add(long.Parse(lstBak[p].ToString() + k.ToString()));        // 後に付加した新しい値
                        }
                    }
                }
                lstNxt = lstNxt.Distinct().ToList();                                            // 重複値排除
                lstNxt.Sort();                                                                  // ソート
                lstBak = new List<long>();
                lstBak.AddRange(lstNxt);                                                        // 元の値にする
                lstTbl.AddRange(lstNxt);                                                        // 保持
                lstNxt = new List<long>();
            }

            // 出力
            System.Console.WriteLine("{0}", lstTbl[iK - 1].ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            //DebugDisp(lstTbl);
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

        // Debug表示
        private static void DebugDisp(List<long> lstTbl)
        {
            System.Console.WriteLine("{0}", "".ToString().Trim());
            System.Console.WriteLine("Count={0}", lstTbl.Count.ToString().Trim());
            for (int i = 0; i < lstTbl.Count; i++)                          // 分割後グループ毎
            {
                System.Console.WriteLine("{0}", lstTbl[i].ToString().Trim());
                if (i > 9800) { break; }
            }
        }

}