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.



Sample input:
15


Sample output:
23

Submission status: Wrong Answer

Solution code:
K = int(input())

dp = [[0 for i in range(10)] for j in range(100)]

for i in range(10):
  dp[1][i] = i
dp[1][0] = 1

p = 1
c = 0
a = 0

while c == 0:
  for n in range(10):
    if n != 0 and n != 9:
      dp[p+1][n] = dp[p][n]+dp[p][n-1]+dp[p][n+1]+dp[p][9]
    if n == 9:
      dp[p+1][n] = dp[p][n]+dp[p][n-1]+dp[p][9]
    if dp[p+1][n] >= K:
      c = dp[p+1][n]
      if a == 1:
        a = n
      break
    #0の追加は最後
    if n == 0:
      dp[p+1][n] = dp[p][1] + dp[p][0]

s = str(a)
for k in range(p,0,-1):

  if a != 0 and a != 9:
    for j in [1,0,-1]:
      c = c - dp[k][a+j]
      if c < K:
        s = s + str(a+j)
        break
  
  if a == 0:
    for j in [1,0]:
      c = c - dp[k][a+j]
      if c < K:
        s = s + str(a+j)
        break

  if a == 9:
    for j in [0,-1]:
      c = c - dp[k][a+j]
      if c < K:
        s = s + str(a+j)
        break       
print(int(s))

Submission status: Wrong Answer

Solution code:
k = int(input())
time = 1

dp0 = [1]#0,9
dp1 = [8]#1~8
p = [9]

for i in range(100):
    dp0.append(dp0[i]*2 + 2)
    dp1.append(dp1[i]*3 - 2)
    p.append(dp0[i+1] + dp1[i+1] + p[i])

    if p[len(p)-1] > k:
        break

#print(len(p))
s = k - p[len(p)-2]
w = [0]*len(p)
print(s,w)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)


k = int(input())
number = 9

ans = 0
for i in range(10,10**5):
    check = 'OK'
    l = len(str(i))
    keta = list(str(i))
    for j in range(l-1):
        if abs(int(keta[j]) - int(keta[j+1])) <= 1:
            pass
        else:
            check = 'NG'
    if check == 'OK':
        number += 1
        if number == k:
            ans = i
            break
    
if k <= 9:
    print(k)
else:
    print(ans)