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:
    
def make_tree(G,keta,count):
    if keta==1:
        num =[]
        for i in range(1,10):
            count+=1
            if count ==k:
                print(i)
                exit()
            else:
                num.append(i)
        G.append(num)
        make_tree(G,2,count)
    else:
        print(G)
        num_list = G[keta-2]
        num_lis =[]
        for num in num_list:
            num_str = str(num)
            num_e = int(num_str[-1])
            if num_e == 0:
                count +=1
                if count == k :
                    print(int(num_str + "0"))
                    exit()
                num_lis.append(int((num_str)+"0"))
                count+=1
                if count == k :
                    print(int(num_str + "1"))
                    exit()
                num_lis.append(int((num_str)+"1"))
            elif num_e == 9:
                count +=1
                if count == k :
                    print(int(num_str + "8"))
                    exit()
                num_lis.append(int((num_str)+"8"))
                count+=1
                if count == k :
                    print(int(num_str + "9"))
                    exit()
                num_lis.append(int((num_str)+"9"))
            else:
                count +=1
                if count == k :
                    print(int(num_str + str(num_e-1)))
                    exit()
                num_lis.append(int(num_str + str(num_e-1)))
                count+=1
                if count == k :
                    print(int(num_str + str(num_e)))
                    exit()
                num_lis.append(int(num_str + str(num_e)))
                count+=1
                if count == k :
                    print(int(num_str + str(num_e+1)))
                    exit()
                num_lis.append(int(num_str + str(num_e+1)))
        G.append(num_lis)

        make_tree(G,keta+1,count)


k = int(input())
G=[]
make_tree(G,1,0)

Submission status: Wrong Answer

Solution code:
K = int(input())


dp = [[1 for _ in range(10)]]
dp
s = [[sum(dp[0][1:i + 1]) for i in range(1, 10)]]
ends = s[0][8]

for j in range(10 * 5):
    dp.append([dp[j][0] + dp[j][1]] + [dp[j][i - 1] + dp[j][i] + dp[j][i + 1]
                                       for i in range(1, 9)] + [dp[j][8] + dp[j][9]])
    s.append([ends + sum(dp[j + 1][1:i + 1]) for i in range(1, 10)])
    ends = s[j + 1][8]
    if ends > 10**5:
        break


def search(jj, ii, m):
    if jj == 0:
        return ii
    else:
        if ii != 0:
            if m <= dp[jj - 1][ii - 1]:
                return (ii) * 10**jj + search(jj - 1, ii - 1, m)
            elif m <= dp[jj - 1][ii - 1] + dp[jj - 1][ii]:
                return (ii) * 10**jj + search(jj - 1, ii, m - dp[jj - 1][ii - 1])
            else:
                return (ii) * 10**jj + search(jj - 1, ii + 1, m - dp[jj - 1][ii - 1] - dp[jj - 1][ii])
        else:
            if m <= dp[jj - 1][ii - 1] + dp[jj - 1][ii]:
                return (ii) * 10**jj + search(jj - 1, ii, m)
            else:
                return (ii) * 10**jj + search(jj - 1, ii + 1, m - dp[jj - 1][ii])


for j in range((len(s))):
    if s[j][8] >= K:
        jj = j
        break
for i in range(9):
    if s[jj][i] >= K:
        ii = i + 1
        if ii > 1:
            m = K - s[jj][i - 1]  # 該当するところの文字で始まる何番目の数かを取得
        else:
            m = K - s[jj - 1][8]
        break

print(search(jj, ii, m))

Submission status: Wrong Answer

Solution code:
k=int(input())

if k <= 12:
    print(k)
    exit()
number = k-12
a,b = divmod(number,3)
if b==0:
    b=3
elif b==1:
    b=2
else:
    b=3
print(str(a+1)+str(b))

Submission status: Wrong Answer

Solution code:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))

# print("Yes")
# print("No")

# print("YES")
# print("NO")



K = int(input())
li = []
li1 = [1 for i in range(11)]
li1[0] = 0
li.append(li1)
li2 = [0 for i in range(11)]
li.append(li2)

while(1):
    li2[0] = sum(li1)-li1[10]
    for i in range(1,10):
        li2[i] = li1[i-1]+li1[i]+li1[i+1]
    li2[10] = li1[1]+li1[9]+li1[10]
    li2[1] = li1[10]+li1[1]+li1[2]
    if sum(li2) >= K:
        break
    li1 = li2.copy()
    li.append(li2)
# print(li)
for i in range(len(li)-1,-1,-1):
    mm = 0
    for j in range(len(li[i])):
        mm += li[i][j]
        if mm >= K:
            # print(j,mm,K,li[i][j])
            print(j,end="")
            K -= mm-li[i][j]
            break
print()

Submission status: Wrong Answer

Solution code:
x = [1,2,3,4,5,6,7,8,9]
for i in range(100000):
  stri = str(i)
  le = len(stri)
  p = [int(stri[j]) for j in range(le)]
  for k in range(le - 1):
    if abs(p[k] -p[k+1]) <= 1:
      x.extend([i])




n = int(input())
print(x[n-1])

Submission status: Wrong Answer

Solution code:
    
def make_tree(G,keta,count):
    if keta==1:
        num =[]
        for i in range(1,10):
            count+=1
            if count ==k:
                print(i)
                exit()
            else:
                num.append(i)
        G.append(num)
        make_tree(G,2,count)
    else:
        print(G)
        num_list = G[keta-2]
        num_lis =[]
        for num in num_list:
            num_str = str(num)
            num_e = int(num_str[-1])
            if num_e == 0:
                count +=1
                if count == k :
                    print(int(num_str + "0"))
                    exit()
                num_lis.append(int((num_str)+"0"))
                count+=1
                if count == k :
                    print(int(num_str + "1"))
                    exit()
                num_lis.append(int((num_str)+"1"))
            elif num_e == 9:
                count +=1
                if count == k :
                    print(int(num_str + "8"))
                    exit()
                num_lis.append(int((num_str)+"8"))
                count+=1
                if count == k :
                    print(int(num_str + "8"))
                    exit()
                num_lis.append(int((num_str)+"9"))
            else:
                count +=1
                if count == k :
                    print(int(num_str + str(num_e-1)))
                    exit()
                num_lis.append(int(num_str + str(num_e-1)))
                count+=1
                if count == k :
                    print(int(num_str + str(num_e)))
                    exit()
                num_lis.append(int(num_str + str(num_e)))
                count+=1
                if count == k :
                    print(int(num_str + str(num_e+1)))
                    exit()
                num_lis.append(int(num_str + str(num_e+1)))
        G.append(num_lis)

        make_tree(G,keta+1,count)


k = int(input())
G=[]
make_tree(G,1,0)

Submission status: Wrong Answer

Solution code:
K = int(input())
A = [1,2,3,4,5,6,7,8,9]
for i in range(len(A)):
    if A[i] != 9:
        for j in range(-1,2):
            a = int(str(A[i]) + str(A[i]+j))
            A.append(a)
    else:
        A.append(98)
        A.append(99)
L1 = len(A.copy())
for i in range(10,L1):
    B = A[i]
    if B % 10 == 0:
        A.append(int(str(B) + '0'))
        A.append(int(str(B) + '1'))
    elif B % 10 == 9:
        A.append(int(str(B) + '8'))
        A.append(int(str(B) + '9'))
    else:
        for j in range(-1, 2):
            a = int(str(B) + str((B % 10) + j))
            A.append(a)
L2 = len(A.copy())
for i in range(L1,L2):
    B = A[i]
    if B % 10 == 0:
        A.append(int(str(B) + '0'))
        A.append(int(str(B) + '1'))
    elif B % 10 == 9:
        A.append(int(str(B) + '8'))
        A.append(int(str(B) + '9'))
    else:
        for j in range(-1, 2):
            a = int(str(B) + str((B%10) + j))
            A.append(a)
L3 = len(A.copy())
for i in range(L2,L3):
    B = A[i]
    if B % 10 == 0:
        A.append(int(str(B) + '0'))
        A.append(int(str(B) + '1'))
    elif B % 10 == 9:
        A.append(int(str(B) + '8'))
        A.append(int(str(B) + '9'))
    else:
        for j in range(-1, 2):
            a = int(str(B) + str((B % 10) + j))
            A.append(a)
L4 = len(A.copy())
for i in range(L3,L4):
    B = A[i]
    if B % 10 == 0:
        A.append(int(str(B) + '0'))
        A.append(int(str(B) + '1'))
    elif B % 10 == 9:
        A.append(int(str(B) + '8'))
        A.append(int(str(B) + '9'))
    else:
        for j in range(-1, 2):
            a = int(str(B) + str((B % 10) + j))
            A.append(a)
L5 = len(A.copy())
for i in range(L4,L5):
    B = A[i]
    if B % 10 == 0:
        A.append(int(str(B) + '0'))
        A.append(int(str(B) + '1'))
    elif B % 10 == 9:
        A.append(int(str(B) + '8'))
        A.append(int(str(B) + '9'))
    else:
        for j in range(-1, 2):
            a = int(str(B) + str((B % 10) + j))
            A.append(a)
L6 = len(A.copy())
for i in range(L5,L6):
    B = A[i]
    if B % 10 == 0:
        A.append(int(str(B) + '0'))
        A.append(int(str(B) + '1'))
    elif B % 10 == 9:
        A.append(int(str(B) + '8'))
        A.append(int(str(B) + '9'))
    else:
        for j in range(-1, 2):
            a = int(str(B) + str((B % 10) + j))
            A.append(a)
L7 = len(A.copy())
for i in range(L6,L7):
    B = A[i]
    if B % 10 == 0:
        A.append(int(str(B) + '0'))
        A.append(int(str(B) + '1'))
    elif B % 10 == 9:
        A.append(int(str(B) + '8'))
        A.append(int(str(B) + '9'))
    else:
        for j in range(-1, 2):
            a = int(str(B) + str((B % 10) + j))
            A.append(a)
L8 = len(A.copy())
for i in range(L7,L8):
    B = A[i]
    if B % 10 == 0:
        A.append(int(str(B) + '0'))
        A.append(int(str(B) + '1'))
    elif B % 10 == 9:
        A.append(int(str(B) + '8'))
        A.append(int(str(B) + '9'))
    else:
        for j in range(-1, 2):
            a = int(str(B) + str((B % 10) + j))
            A.append(a)
print(sorted(A)[K-1])

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate
K = int(input())

MAX = 22
dp = [[0]*10 for _ in [0]*MAX]

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

for i in range(2, MAX):
    for j in range(1, 9):
        dp[i][j] = dp[i-1][j-1] + dp[i-1][j] + dp[i-1][j+1]
    dp[i][0] = dp[i-1][0] + dp[i-1][1]
    dp[i][9] = dp[i-1][8] + dp[i-1][9]

acc = [[] for _ in [0]*MAX]
for i in range(1, MAX):
    acc[i] = accumulate(dp[i])

# i桁で最大のルンルン数(99...9)は何番目か
num = [0]
for i in range(1, MAX):
    num.append(num[i-1] + sum(dp[i][1:]))

cnt = 0
for i, n in enumerate(num):
    if n < K:
        keta = i+1
        cnt = n
    else:
        break

ans = 0

rg = range(1, 10)
p = 1
for i in range(keta, 0, -1):
    for j in rg:
        if cnt + dp[i][j] < K:
            flg = True
            p = j+1
            cnt += dp[i][j]
        else:
            break

    ans += 10**(i-1)*p

    rg = range(max(0, p-1), min(10, p+2))
    p = p-1

print(ans)

Submission status: Wrong Answer

Solution code:
K = input()
data_lun = 0
count = 0
for j in range(100000):
  word = [int(k) for k in str(j)]
  sa = []
  if len(word) == 1:
    data_lun = j
    count += 1
  else:
    for l in range(len(word)-1):
      result = abs(word[l+1]-word[l])
      sa.append(result)
    if max(sa) <= 1:
      data_lun = j
      count += 1
  if count -1 == int(K):
    break
print(data_lun)

Submission status: Wrong Answer

Solution code:
a=int(input())
run=[0]*a
cnt=1
cn=0
while 1:
    b=cnt%10
    c=(cnt%100)//10
    if(((b-c)==-1)or((b-c==1))or((b-c==0)))or(cnt<=10):
        run[cn]=cnt
        cn=cn+1
    cnt=cnt+1
    if cn==a:
        break
print(max(run))

Submission status: Wrong Answer

Solution code:
K = int(input())


dp = [[1 for _ in range(10)]]
dp
s = [[sum(dp[0][1:i + 1]) for i in range(1, 10)]]
ends = s[0][8]

for j in range(10 * 5):
    dp.append([dp[j][0] + dp[j][1]] + [dp[j][i - 1] + dp[j][i] + dp[j][i + 1]
                                       for i in range(1, 9)] + [dp[j][8] + dp[j][9]])
    s.append([ends + sum(dp[j + 1][1:i + 1]) for i in range(1, 10)])
    ends = s[j + 1][8]
    if ends > 10**5:
        break


def search(jj, ii, m):
    if jj == 0:
        return ii
    else:
        if ii != 0:
            if m <= dp[jj - 1][ii - 1]:
                return (ii) * 10**jj + search(jj - 1, ii - 1, m)
            elif m <= dp[jj - 1][ii - 1] + dp[jj - 1][ii]:
                return (ii) * 10**jj + search(jj - 1, ii, m - dp[jj - 1][ii - 1])
            else:
                return (ii) * 10**jj + search(jj - 1, ii + 1, m - dp[jj - 1][ii - 1] - dp[jj - 1][ii])
        else:
            return (ii) * 10**jj + search(jj - 1, ii , m - dp[jj - 1][ii - 1])


for j in range((len(s))):
    if s[j][8] >= K:
        jj = j
        break
for i in range(9):
    if s[jj][i] >= K:
        ii = i + 1
        if ii > 1:
            m = K - s[jj][i - 1]  # 該当するところの文字で始まる何番目の数かを取得
        else:
            m = K - s[jj - 1][8]
        break

print(search(jj, ii, m))

Submission status: Wrong Answer

Solution code:
def count_lunlun(num):
    num = list(map(int, str(num)))
    d = len(num)
    dp = [[[[0] * 10 for _ in range(2)] for _ in range(2)] for _ in range(d + 1)]
    dp[0][0][0][0] = 1
    for i in range(d):
        for j in range(2):
            for k in range(10):
                for z in range(2):
                    for x in range(10 if j else (num[i] + 1)):
                        if abs(x - k) <= 1:
                            dp[i + 1][j or x < num[i]][x != 0][x] += dp[i][j][z][k]
                        elif z == 0:
                            dp[i + 1][j or x < num[i]][x != 0][x] += dp[i][j][z][k]
    return sum(dp[d][0][0]) + sum(dp[d][0][1]) + sum(dp[d][1][0]) + sum(dp[d][1][1]) - 1


K = int(input())
left = 0
right = 10 ** 12
while right - left > 1:
    mid = (left + right) // 2
    count = count_lunlun(mid)
    if count >= K:
        right = mid
    else:
        left = mid
print(right)

Submission status: Wrong Answer

Solution code:
k = int(input())
if k <= 9:
    print(k)
else:
    c = 10
    n = 10
    while True:
        p = n % 10
        v = n // 10
        r = True
        print("{} {} {}".format(c,n,v))
        while v > 0:
            nv = v % 10
            if abs(nv - p) > 1:
                r = False
                break
            else:
                p = nv
                v = v // 10
        if r:
            if c == k:
                print(n)
                break
            c += 1
        n += 1

Submission status: Wrong Answer

Solution code:
import math
k = int(input())

if(k <= 12):
  print(k)
  exit()
  

n = 9 + (3*9)
cnt = 2

num = [3**i for i in range(40)]
ns = []
for i in range(len(num)):
  
  ns.append(sum(num[0:i]))
ns.pop(0)

l = 10

if(k <= n):
  for i in range(1,9):
    for j in range(0,9):
      if(abs(i - j) > 1):
        continue
      s = i * 10 + j
      if(l == k):
        print(s)
      l += 1

while(n < k):
  cnt += 1
  n += (9 * (num[cnt]))
  for i in range(cnt-1):
    print(i)
    if(i == cnt - 2):
      n -= ns[i]
    else:
      n -= ns[i] * 2
  
a = n
n -= (9 * (num[cnt])) - (ns[cnt-3] + ns[cnt-2])

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate
K = int(input())

MAX = 22
dp = [[0]*10 for _ in [0]*MAX]

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

for i in range(2, MAX):
    for j in range(1, 9):
        dp[i][j] = dp[i-1][j-1] + dp[i-1][j] + dp[i-1][j+1]
    dp[i][0] = dp[i-1][0] + dp[i-1][1]
    dp[i][9] = dp[i-1][8] + dp[i-1][9]

acc = [[] for _ in [0]*MAX]
for i in range(1, MAX):
    acc[i] = accumulate(dp[i])

# i桁で最大のルンルン数(99...9)は何番目か
num = [0]
for i in range(1, MAX):
    num.append(num[i-1] + sum(dp[i][1:]))

print(dp[:6])
print(num)

cnt = 0
for i, n in enumerate(num):
    if n < K:
        keta = i+1
        cnt = n
    else:
        break

print(keta, cnt)
ans = 0

rg = range(1, 10)
p = 1
for i in range(keta, 0, -1):
    for j in rg:
        print('keta', i, 'suuji', j, 'cnt', cnt, 'dp', dp[i][j], 'ans', ans)
        if cnt + dp[i][j] < K:
            flg = True
            p = j+1
            cnt += dp[i][j]
        else:
            break

    ans += 10**(i-1)*p

    rg = range(max(0, p-1), min(10, p+2))
    p = p-1

print(ans)

Submission status: Wrong Answer

Solution code:
c=11
i=11
a = int(input())
if a>11:
    while i<3234566668:
        i+=1
        f=0
        l = [int(x) for x in list(str(i))]
        for j in range(1,len(str(i))):
            if abs(l[j-1]-l[j])>1:
                f=1
            if l[j-1]-l[j]<-1:
                i+=8*10**(len(str(i))-j-1)-1
        if f==0:
            c+=1
        if c==a:
            print(i)
            break
else:
    print(a)

Submission status: Wrong Answer

Solution code:
def is_runrun(n):
    global runrun
    s = str(n)
    if len(s) == 1:
        return True

    if abs(int(s[0]) - int(s[1])) > 1:
        return False

    if int(s[1:]) not in runrun and int(s[1:]) != 0:
        return False

    return True


K = int(input())

runrun = [None] * K
k = 0
i = 1
while True:
    if is_runrun(i):
        runrun[k] = i
        k += 1
        if k == K:
            print(i)
            break
    i += 1

Submission status: Wrong Answer

Solution code:
# coding: utf-8
K = int(input())
queue = [str(i) for i in range(1, 10)]
# print(queue)
L = []
while queue:
    v = queue.pop(0)
    L.append(int(v))
    if v[-1] == "0":
        # print("v =", v)
        queue.append(v + v[-1])
        queue.append(v+"1")
        
    elif v[-1] == "9":
        # print("9", v)
        queue.append(v + "8")
        queue.append(v + v[-1])
    else:
        # print("else", v)
        t = int(v[-1])
        queue.append(v+str(t-1))
        queue.append(v+str(t+1))
        queue.append(v + v[-1])
    if len(L) >= K:
        break
L.sort()
# print()
# print(L[-39:])
print(L[K-1])

Submission status: Wrong Answer

Solution code:
K = int(input())


dp = [[1 for _ in range(10)]]
dp
s = [[sum(dp[0][1:i + 1]) for i in range(1, 10)]]
ends = s[0][8]

for j in range(10 * 5):
    dp.append([dp[j][0] + dp[j][1]] + [dp[j][i - 1] + dp[j][i] + dp[j][i + 1]
                                       for i in range(1, 9)] + [dp[j][8] + dp[j][9]])
    s.append([ends + sum(dp[j + 1][1:i + 1]) for i in range(1, 10)])
    ends = s[j + 1][8]
    if ends > 10**5:
        break


def search(jj, ii, m):
    if jj == 0:
        return ii
    else:
        if ii != 0:
            if m <= dp[jj - 1][ii - 1]:
                return (ii) * 10**jj + search(jj - 1, ii - 1, m)
            elif m <= dp[jj - 1][ii - 1] + dp[jj - 1][ii]:
                return (ii) * 10**jj + search(jj - 1, ii, m - dp[jj - 1][ii - 1])
            else:
                return (ii) * 10**jj + search(jj - 1, ii + 1, m - dp[jj - 1][ii - 1] - dp[jj - 1][ii])
        else:
            return (ii) * 10**jj + search(jj - 1, ii + 1, m - dp[jj - 1][ii - 1])


for j in range((len(s))):
    if s[j][8] >= K:
        jj = j
        break
for i in range(9):
    if s[jj][i] >= K:
        ii = i + 1
        if ii > 1:
            m = K - s[jj][i - 1]  # 該当するところの文字で始まる何番目の数かを取得
        else:
            m = K - s[jj - 1][8]
        break

print(search(jj, ii, m))

Submission status: Wrong Answer

Solution code:
K = int(input())

lunlun=1
cnt =1
flg=0

while True:
    S=str(lunlun)
    flg=0
    if len(S)==1:
        lunlun+=1
        cnt+=1
    else:
        for j in range(len(S)-1):
            if abs(int(S[j])-int(S[j+1]))<=1:
                flg+=1
        if flg==len(S)-1:
            lunlun+=1
            cnt+=1
        else:
            lunlun+=1
    
    if cnt==K:
        print(lunlun)
        exit(0)

Submission status: Wrong Answer

Solution code:
def get_lunlun(limit):
    ans = []

    while True:
        for i in range(1, 10 ** 6):
            if len(str(i)) == 1:
                ans.append(i)
            else:
                s = str(i)
                le = len(s)

                valid = True
                for l in range(le - 1):
                    if not valid:
                        continue

                    if abs(int(s[l]) - int(s[l + 1])) > 1:
                        valid = False

                if valid:
                    ans.append(i)

            if len(ans) >= limit:
                return ans


def main(k: int):
    print(get_lunlun(k)[-1])


if __name__ == "__main__":
    k = int(input())
    main(k)

Submission status: Wrong Answer

Solution code:
K = int(input())  #数字

if K <= 12:
    print(K)
    exit()

num = 13
cou = 12
cal = 1
while cou < K:
    L = list(map(int, str(num)))  #iの各行を数字としてリストに格納し合計
    #print("num",num)
    for i in range(len(L) - 1):
        if abs(L[i] - L[i + 1]) > 1:
            num += 1
            break
        else:
            if cal == len(L) - 1:
                cou += 1
                num += 1                
            else:
                cal += 1
    #print(cou)
print(num-1)

Submission status: Wrong Answer

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

if 1 <= k and k <= 9:
    print(k)

Submission status: Wrong Answer

Solution code:
from collections import deque
k = int(input())
que = deque(["1","2","3","4","5","6","7","8","9"])
c = 0
flag = True
visited = set()
res=[]
if k<=9:
    print(que[k])
else:
    while flag and len(que)!=0:
        n = len(que)
        for i in range(n):
            temp = que.popleft()
            res.append(temp)
            visited.add(temp)
            c+=1
            if int(int(temp[-1])-1)>=0:
                pot1 = str(temp) + str(int(int(temp[-1])-1))
                if pot1 not in visited:
                    que.append(pot1)
                    visited.add(pot1)
            pot2 = str(temp)+ str(temp[-1])
            
            if pot2 not in visited:
                que.append(pot2)
                visited.add(pot1)
            if int(temp[-1])==9:
                pass
            else:
                pot3 = temp+str(int(temp[-1])+1)
                if pot3 not in visited:
                    que.append(pot3)
                    visited.add(pot1)
            if c==k:
                flag = False
                break
    print(int(res[-1]))

Submission status: Wrong Answer

Solution code:
k=int(input(''))
r=[]
def detr(n):
    sn=str(n)
    j=0
    for a in sn:
        j=j+1
    
    if j==1:
        return True

    ok=1
    for a in range(j-1):
        if int(sn[a])-int(sn[a+1])==0 or int(sn[a])-int(sn[a+1])==1 or int(sn[a])-int(sn[a+1])==-1:
            ok=ok*1
        else:
            ok=ok*0
            break
    
    if ok==1:
        return True
    else:
        return False

lis=[]
x=1
c=0
while len(lis)<k:
    if detr(x)==True:
        lis.append(x)
        if x>=10:
            c=c+1
    
    if c<=2:
        x=x+1
    else:
        c=0
        x=x+9

print(lis[-1])

Submission status: Wrong Answer

Solution code:
def lunlun(n):
    s=str(n)
    for i in range(len(s)-1):
        if(abs(int(s[i])-int(s[i+1]))>1):
            return False
    return True
def calc(k):
    n=1
    i=1
    while(n<k):
        if(lunlun(i)):

            n=n+1
        i=i+1
    return i
print(calc(15))

Submission status: Wrong Answer

Solution code:
k = int(input())

ls = [[0,1,1,1,1,1,1,1,1,1]]
size = 9

while size<k:
  k -= size
  tmp = [0]*10
  for i in range(10):
    if i == 0:
      tmp[i] = ls[-1][i]+ls[-1][i+1]
    elif i == 9:
      tmp[i] = ls[-1][i-1]+ls[-1][i]
    else:
      tmp[i] = ls[-1][i-1]+ls[-1][i]+ls[-1][i+1]
  ls.append(tmp[:])
  size = sum(ls[-1])
  
ans = ""

start = 0
end = 10

for a in ls[::-1]:
  for i in range(start,end):
    if k > a[i]:
      k -= a[i]
    else:
      ans += str(i)
      start = max(0,i-1)
      end = min(10,i+2)
      break
  
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
now=[1,2,3,4,5,6,7,8,9]
if n<10:
  print(now[n-1])
  exit()
cnt=9
while True:
  next=[]
  for s in now:
    s=str(s)
    if s[-1]!=0:
      cnt+=1
      if cnt<n:
        next.append(s+"0")
      else:
        print(s+"0")
        exit()
    cnt+=1
    if cnt<n:
      next.append(s+s[-1])
    else:
      print(s+s[-1])
      exit()
    if s[-1]!=9:
      cnt+=1
      if cnt<n:
        next.append(s+"9")
      else:
        print(s+"9")
        exit()
  now=next

Submission status: Wrong Answer

Solution code:
k = int(input())

i = 0
n = 0
while True:
  i += 1
  s = str(i)
  for j in range(len(s)-1):
    if (int(s[j]) - int(s[j+1])) not in [-1, 0, 1]:
      i += 7
      break
  else:
    n += 1
    if n == k:
      print(i)
      break

Submission status: Wrong Answer

Solution code:
def main():
    K = int(input())

    if K < 10:
        print(K)
        return

    R = [1,2,3,4,5,6,7,8,9]

    x = 9
    while True:
        T = []
        for r in R:
            if r % 10 > 0:
                T.append(r * 10 + (r % 10) - 1)
                x += 1
                if x >= K:
                    print(r * 10 + (r % 10) - 1)
                    return
            T.append(r * 10 + (r % 10))
            x += 1
            if x >= K:
                print(r * 10)
                return
            if r % 10 < 9:
                T.append(r * 10 + (r % 10) + 1)
                x += 1
                if x >= K:
                    print(r * 10 + (r % 10) + 1)
                    return

        R = T[::]

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
K = int(input())
li = []
li1 = [1 for i in range(10)]
li1[0] = 0
li.append(li1)
li2 = [0 for i in range(10)]
li.append(li2)

while(1):
    li2[0] = sum(li1)
    for i in range(2,9):
        li2[i] = li1[i-1]+li1[i]+li1[i]
    li2[1] = 1+li1[1]+li1[2]
    li2[9] = li1[8]+li1[9]
    if sum(li2) >= K:
        break
    li1 = li2.copy()
    li.append(li2)
# print(li)
for i in range(len(li)-1,-1,-1):
    mm = 0
    for j in range(len(li[i])):
        mm += li[i][j]
        if mm >= K:
            # print(j,mm,K,li[i][j])
            print(j,end="")
            K -= mm-li[i][j]
            break
print()

Submission status: Wrong Answer

Solution code:
k = int(input())

lis = []

while len(lis) <= k:
    test = 1
    if test < 10:
        lis.append(test)
    else:
        for i in range(len(str(test)) - 1):
            truf = True
            if not abs(str(test)[i] - str(test)[i+1]) <= 1:
                truf = False
                break
            if truf:
                lis.append(test)

print(lis[k])

Submission status: Wrong Answer

Solution code:
def dp():
    cnt = []
    for i in range(10):
        cnt.append([0] * 10)
    for i in range(10):
        cnt[0][i] = 1
    for i in range(1, 10):
        for j in range(10):
            cnt[i][j] = 0
            for k in range(-1, 2):
                if 0 <= j+k and j+k < 10:
                    cnt[i][j] += cnt[i-1][j+k]
    return cnt


def main():
    k = int(input())
    cnt = dp()
    tot = [0] * 10
    for i in range(10):
        tot[i] = sum(cnt[i][1:])
    # print(*cnt, sep='\n')
    # print(tot)

    res = 0
    length = -1
    digit = -1
    for i in range(10):
        if tot[i] < k:
            k -= tot[i]
        else:
            length = i
            for j in range(1, 10):
                if k > cnt[i][j]:
                    k -= cnt[i][j]
                else:
                    digit = j
                    break
            break

    length -= 1
    res = digit
    while length >= 0:
        for i in range(-1, 2):
            if 0 <= digit + i and digit + i <= 9 and cnt[length][digit + i] >= k:
                digit = digit + i
                break
            else:
                k -= cnt[length][digit + i]
        length -= 1
        res = res * 10 + digit
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
k = int(raw_input())
que = deque(["1","2","3","4","5","6","7","8","9"])
c = 0
flag = True
visited = set()
res=[]
if k<=9:
    print(que[k])
else:
    while flag and len(que)!=0:
        n = len(que)
        for i in range(n):
            temp = que.popleft()
            res.append(temp)
            visited.add(temp)
            c+=1
            if int(int(temp[-1])-1)>=0:
                pot1 = str(temp) + str(int(int(temp[-1])-1))
                if pot1 not in visited:
                    que.append(pot1)
                    visited.add(pot1)
            pot2 = str(temp)+ str(temp[-1])
            
            if pot2 not in visited:
                que.append(pot2)
                visited.add(pot1)
            if int(temp[-1])==9:
                pass
            else:
                pot3 = temp+str(int(temp[-1])+1)
                if pot3 not in visited:
                    que.append(pot3)
                    visited.add(pot1)
            if c==k:
                flag = False
                break
    print(res[-1])

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    K = int(input())

    cnt = 0
    X = 1
    while cnt<K:
        if X<=9:
            # print(X)
            cnt += 1
        else:
            ok = True
            Xstr = str(X)
            for i in range(len(Xstr)-1):
                if abs(int(Xstr[i])-int(Xstr[i+1]))>1:
                    ok = False
            if ok:
                # print(X)
                cnt += 1
        X += 1
    print(X-1)

Submission status: Wrong Answer

Solution code:
k = int(input())

lis = []

while len(lis) <= k:
    test = 1
    if test < 10:
        lis.append(test)
    else:
        for i in range(len(str(test)) - 1):
            if abs(str(test)[i] - str(test)[i+1]) <= 1:
                lis.append(test)

print(lis[k])

Submission status: Wrong Answer

Solution code:
import sys
import numpy


k = int(input())

counter = 13
if k < 13 :
    print(k)
else :
    for i in range(13, k**3) :
        counter += 1
        nums = list(map(int, list(str(i))))
        diff = numpy.array(nums[1:]) - numpy.array(nums[:-1])
        if max(diff) > 1 or min(diff) < -1 :
            counter -= 1

        if counter == k :
            print(i+1)
            sys.exit()