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:
from collections import deque

k = 100
count = 0
q = deque(range(1,10))

while count < k:
    l = q.popleft()
    resid = l % 10
    if resid != 0: q.append(l*10 + resid - 1)

    q.append(l*10 + resid)
    
    if resid != 9: q.append(l*10 + resid + 1)
    
    count += 1

print(q[k-1])

Submission status: Wrong Answer

Solution code:
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:input()

"""========main code==============="""

x=ii()
lol=[1,2,3,4,5,6,7,8,9]
ans=9
if(x>9):
    for i in lol:
        k=str(i)
        a=int(k[len(k)-1])
        if(a-1>=0):
            lol.append(k+str(a-1))
            ans+=1
            if(ans==x):
                print(lol[x-1])
                break
        lol.append(k+str(a))
        ans+=1
        if(ans==x):
            print(lol[x-1])
            break
        if(a+1<=9):
            lol.append(k+str(a+1))
            ans+=1    
            if(ans==x):
                print(lol[x-1])
                break
else:
    print(x-1)

Submission status: Wrong Answer

Solution code:
k = int(input())
q = []
for i in range(1, 10):
    q.append(i)
for i in range(k):
    x = q.pop(0)
    if x % 10 != 0:
        q.append(10 * x + x % 10 - 1)
    q.append(10 * x + x % 10)
    if x % 10 != 9:
        q.append(10 * x + x % 10 + 1)
    # print(q)

Submission status: Wrong Answer

Solution code:
import queue
K = int( input() )

q = queue.Queue()

ret = K
for i in range( 1, 9 + 1 ):
  q.put( i )

number_of_operations = 9
while number_of_operations < K:
  i = q.get()
  k = i % 10 
  if k != 0:
    ret = 10 * i + k - 1
    q.put( ret )
    number_of_operations += 1
  ret = 10 * i + k
  q.put( ret )
  number_of_operations += 1
  if k != 9:
    ret = 10 * i + k + 1
    q.put( ret )
    number_of_operations += 1

print( ret )

Submission status: Wrong Answer

Solution code:
import queue
k=int(input())
q=queue.Queue()
for i in range(1,10):
  q.put(i)
c=0
while c<k:
  a=q.get()
  c+=1
  print("{}番目:{}".format(c,a))
  if c==k:
    print(a)
  if (a%10)!=0:
    q.put(10*a+a%10-1)
  q.put(10*a+a%10)
  if (a%10)!=9:
    q.put(10*a+a%10+1)

Submission status: Wrong Answer

Solution code:
K = 12
table = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in table:
  if len(table) > K:
    break
  x = i % 10
  for j in range(max(0, x - 1), min(x + 2, 10)):
    table.append(i * 10 + j)

print(table[K-1])

Submission status: Wrong Answer

Solution code:

K = input("")
K = int(K)
m = 0
n = 0

if 10 <= K < 36:
    n = 10-1
    m = 10
elif 36 <= K < 112: 
    n = 100-1
    m = 36
elif 112 <= K:
    n = 1000-1
    m = 112


while(m != K):
    n += 1
    ns = str(n)
    if n < 10:
        m += 1
    elif 10<=n<100:
        n1 = int(str(ns[-1]))
        n2 = int(str(ns[-2]))
        if -1 <= n1-n2 <= 1:
            m += 1
    elif 100<=n<1000:
        n1 = int(str(ns[-1]))
        n2 = int(str(ns[-2]))
        n3 = int(str(ns[-3]))
        if -1 <= n1-n2 <= 1 and -1 <= n2-n3 <= 1 :
            m += 1
    elif 1000<=n<10000:
        n1 = int(str(ns[-1]))
        n2 = int(str(ns[-2]))
        n3 = int(str(ns[-3]))
        n4 = int(str(ns[-4]))
        if -1 <= n1-n2 <= 1 and -1 <= n2-n3 <= 1 and -1 <= n3-n4 <= 1 :
            m += 1
    elif 10000<=n<=100000:
        n1 = int(str(ns[-1]))
        n2 = int(str(ns[-2]))
        n3 = int(str(ns[-3]))
        n4 = int(str(ns[-4]))
        n5 = int(str(ns[-5]))
        if -1 <= n1-n2 <= 1 and -1 <= n2-n3 <= 1 and -1 <= n3-n4 <= 1 and -1 <= n4-n5 <= 1:
            m += 1

    
    if m == K:
        break

print(n)

Submission status: Wrong Answer

Solution code:
import sys
from _collections import deque

K = int(input())
c = 9
A = [1,2,3,4,5,6,7,8,9]
q = deque(A)

if K <= 9:
    print(K)
else:
    while(True):
        a = q.popleft()
        if a % 10 == 0:
            c += 1
            if c == K:
                print(a*10)
                sys.exit()
            q.append(a*10)
            c += 1
            if c == K:
                print(a*10+1)
                sys.exit()
            q.append(a*10+1)
        elif a % 10 == 9:
            c += 1
            if c == K:
                print(a*10-1)
                sys.exit()
            q.append(a*10-1)
            c += 1
            if c == K:
                print(a*10)
                sys.exit()
            q.append(a*10)
        else:
            c += 1
            if c == K:
                print(a*10-1)
                sys.exit()
            q.append(a*10-1)
            c += 1
            if c == K:
                print(a*10)
                sys.exit()
            q.append(a*10)
            c += 1
            if c == K:
                print(a*10+1)
                sys.exit()
            q.append(a*10+1)

Submission status: Wrong Answer

Solution code:
import queue

q = queue.Queue()
K = int(input())

for i in range(1, 10):
    q.put(i)

for i in range(K):
    x = q.get()
    r =  x % 10
    if r != 0:
        q.put((10 * x) + (r-1))
    q.put(10 * x)
    if x % 10 != 9:
        q.put((10 * x) + (r+1))

print(x)

Submission status: Wrong Answer

Solution code:

K = input("")
K = int(K)
m = 0
n = 1
if 10 <= K < 36:
    n = 10
    m = 10
elif 36 <= K < 112: 
    n = 100
    m = 36
elif 112 <= K:
    n = 1000
    m = 112


while(m != K):
    ns = str(n)
    if n < 10:
        m += 1
    elif 10<=n<100:
        n1 = int(str(ns[-1]))
        n2 = int(str(ns[-2]))
        if -1 <= n1-n2 <= 1:
            m += 1
    elif 100<=n<1000:
        n1 = int(str(ns[-1]))
        n2 = int(str(ns[-2]))
        n3 = int(str(ns[-3]))
        if -1 <= n1-n2 <= 1 and -1 <= n2-n3 <= 1 :
            m += 1
    elif 1000<=n<10000:
        n1 = int(str(ns[-1]))
        n2 = int(str(ns[-2]))
        n3 = int(str(ns[-3]))
        n4 = int(str(ns[-4]))
        if -1 <= n1-n2 <= 1 and -1 <= n2-n3 <= 1 and -1 <= n3-n4 <= 1 :
            m += 1
    elif 10000<=n<=100000:
        n1 = int(str(ns[-1]))
        n2 = int(str(ns[-2]))
        n3 = int(str(ns[-3]))
        n4 = int(str(ns[-4]))
        n5 = int(str(ns[-5]))
        if -1 <= n1-n2 <= 1 and -1 <= n2-n3 <= 1 and -1 <= n3-n4 <= 1 and -1 <= n4-n5 <= 1:
            m += 1
    n += 1
    
    if m == K:
        break

print(n)

Submission status: Wrong Answer

Solution code:
K = int(input())
a = 0
count = 0
mm = [0,1]
while True:
    a += 1
    if a == 1:
        for i in range(1,10):
            count += 1
            if count == K:
                print(i)
                exit()

    elif a == 2:
        for i in range(1,10):
            for j in range(0,10):
                if abs(i-j)<=1:
                    count+= 1
                    mm.append(i*10+j)
                    if count == K:
                        print(i*10+j)
                        exit()

    elif a >= 3:
        tmp = [] 
        for i in range(1,10):
            # print(mm)
            for j in mm:
                b = j//(10**(a-2))
                # print(b)
                if abs(i-b) <=1:
                    count+= 1
                    e = i*(10**(a-1))+j
                    # print(count,e)
                    tmp.append(e)
                    if count == K:
                        print(e)
                        exit()
        # print(tmp)
        mm = mm + tmp
#         # print(mm)

#     # if len(mm)>K:
# print(mm)
# print(mm[K-1])

Submission status: Wrong Answer

Solution code:
k = int(input())
if k<10:
  print(k)

a = ["1","2","3","4","5","6","7","8","9"]
i = 0
while len(a)<=k:
  b = a[i]
  c = int(b[-1])
  i += 1
  for j in range(-1,2):
    if 0<=c+j<10:
      a.append(b+str(c+j))

print(a[k-1])

Submission status: Wrong Answer

Solution code:
import sys
import collections
input = sys.stdin.readline
K = int(input())

queue = collections.deque()

for n in range(1, 10):
	queue.append(n)

n = 1
for k in range(K):
	n = queue.popleft()
	if n % 10 != 0:
		queue.append(n * 10 + n - 1)
	queue.append(n * 10 + n)
	if n % 10 != 9:
		queue.append(n * 10 + n + 1)

print(n)

Submission status: Wrong Answer

Solution code:

K = input("")
K = int(K)
m = 0
n = 0

if 10 <= K < 36:
    n = 10
    m = 10
elif 36 <= K < 112: 
    n = 100
    m = 36
elif 112 <= K:
    n = 1000
    m = 112

while(m != K):
    ns = str(n)
    if n < 10:
        m += 1
    elif 10<=n<100:
        n1 = int(str(ns[-1]))
        n2 = int(str(ns[-2]))
        if -1 <= n1-n2 <= 1:
            m += 1
    elif 100<=n<1000:
        n1 = int(str(ns[-1]))
        n2 = int(str(ns[-2]))
        n3 = int(str(ns[-3]))
        if -1 <= n1-n2 <= 1 and -1 <= n2-n3 <= 1 :
            m += 1
    elif 1000<=n<10000:
        n1 = int(str(ns[-1]))
        n2 = int(str(ns[-2]))
        n3 = int(str(ns[-3]))
        n4 = int(str(ns[-4]))
        if -1 <= n1-n2 <= 1 and -1 <= n2-n3 <= 1 and -1 <= n3-n4 <= 1 :
            m += 1
    elif 10000<=n<=100000:
        n1 = int(str(ns[-1]))
        n2 = int(str(ns[-2]))
        n3 = int(str(ns[-3]))
        n4 = int(str(ns[-4]))
        n5 = int(str(ns[-5]))
        if -1 <= n1-n2 <= 1 and -1 <= n2-n3 <= 1 and -1 <= n3-n4 <= 1 and -1 <= n4-n5 <= 1:
            m += 1
    n += 1
    
    if m == K:
        break

print(n)

Submission status: Wrong Answer

Solution code:
K = int(input())
lis = [1,2,3,4,5,6,7,8,9]
for i in range(K+1):
    v = lis.pop(0)
    t = v%10
    s = 10*v
    if t != 0:
        lis.append(s + (t-1))
    lis.append(s + t)
    if t != 9:
        lis.append(s + (t+1))
print(v)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy


def calc_k_th_lunlun_num(K, digit_lunlun_num_list):
    lunlun_num_iterate_num = 9
    digit_num = 1
    while lunlun_num_iterate_num <= K:
        next_digit_lulun_num_list = []
        for next_top_digit_num in range(10):
            for i in range(len(digit_lunlun_num_list)):
                last_digit_lunlun_num = int(digit_lunlun_num_list[i])
                top_digit_num = int(str(last_digit_lunlun_num)[0])
                if abs(next_top_digit_num - top_digit_num) <= 1:
                    if next_top_digit_num != 0:
                        lunlun_num_iterate_num += 1
                    lunlun_num = str(next_top_digit_num) + str(last_digit_lunlun_num).rjust(digit_num, '0')
                    lunlun_num = lunlun_num.rjust(digit_num+1, '0')
                    if lunlun_num_iterate_num == K:
                        return lunlun_num
                    next_digit_lulun_num_list.append(lunlun_num)
        digit_lunlun_num_list = deepcopy(next_digit_lulun_num_list)
        digit_num += 1


def main():
    K = int(input())
    digit_lunlun_num_list = [str(i) for i in range(10)]
    if K < 10:
        print(digit_lunlun_num_list[K])
    else:
        k_th_lunlun_num = calc_k_th_lunlun_num(K, digit_lunlun_num_list)
        print(k_th_lunlun_num)


main()

Submission status: Wrong Answer

Solution code:
a=int(input())
list1=[1,2,3,4,5,6,7,8,9]
i=1
while(i<=a) :
  #print (list1)
  if i!=a :
    k=list1.pop(0)
    k=str(k)
    if int(k[-1])==0 :
      list1.append(int(str(k)+'0'))
      list1.append(int(str(k)+'1'))
    elif int(k[-1])==9 :
      list1.append(int(str(k)+'8'))
      list1.append(int(str(k)+'9'))
    else :
      list1.append(int(str(k)+str(int(k[-1])-1)))
      list1.append(int(str(k)+str(int(k[-1]))))
      list1.append(int(str(k)+str(int(k[-1])+1)))
      i+=1
  else :
    print(list1[0])
    break

Submission status: Wrong Answer

Solution code:
k, = (int(x) for x in input().split())

import functools


@functools.lru_cache(None)
def count10(v, d):
    if d == 1:
        return 1
    x = 0
    if v > 0:
        x += count10(v - 1, d - 1)
    if v < 9:
        x += count10(v + 1, d - 1)

    x += count10(v, d - 1)
    return x


def ff(item):
    kk = [int(c) for c in str(item)]

    sol = 0
    ll = len(kk)
    for l in range(1, ll):
        for v in range(1, 10):
            sol += count10(v, l)

    for i, v in enumerate(kk):
        if i == 0:
            lo = 1
        else:
            lo = kk[i-1]-1
        for x in range(lo, v):
            sol += count10(x, ll - i)
        if i == ll - 1 or kk[i + 1] > v + 1:
            sol += count10(v, ll - i)
            break
        elif kk[i + 1] < v - 1:
            break

    return sol


import bisect


class SearchSol:
    def __getitem__(self, item):
        return ff(item)


sa = SearchSol()
ma = 1
while True:
    ma *= 10
    sol = bisect.bisect_left(sa, k, 1, ma)
    if sol < ma:
        break

print(sol)

Submission status: Wrong Answer

Solution code:
n = int(input())
D = []

def FindOtvet(i, j, otv):
    if i == 0:
        return ''
    if j == 0:
        if (otv + D[i - 1][j]) < n:
            otv += D[i - 1][j]
            return str(j + 1) + FindOtvet(i - 1, j + 1, otv)
        else:
            return str(j) + FindOtvet(i - 1, j, otv)
    elif j == 9:
        if (otv + D[i - 1][j - 1]) < n:
            otv += D[i - 1][j - 1]
            return str(j) + FindOtvet(i - 1, j, otv)
        else:
            return str(j - 1) + FindOtvet(i - 1, j - 1, otv)
    else:
        if (otv + D[i - 1][j - 1]) < n:
            otv += D[i - 1][j - 1]
            if (otv + D[i - 1][j]) < n:
                otv += D[i - 1][j]
                return str(j + 1) + FindOtvet(i - 1, j + 1, otv)
            else:
                return str(j) + FindOtvet(i - 1, j, otv)
        else:
            return str(j - 1) + FindOtvet(i - 1, j - 1, otv)

arr = []
for i in range(10):
    arr.append(1)
D.append(arr)
totalSum = 9
i = 1
respI = 0
respJ = 0
while respI == 0 and respJ == 0:
    arr = []
    for j in range(10):
        if j == 0:
            arr.append(D[i - 1][j] + D[i - 1][j + 1])
        elif j < 9:
            arr.append(D[i - 1][j - 1] + D[i - 1][j] + D[i - 1][j + 1])
        else:
            arr.append(D[i - 1][j - 1] + D[i - 1][j])
        if j > 0:
            if (totalSum + arr[j]) >= n:
                respI = i
                respJ = j
                break
            totalSum += arr[j]
    D.append(arr)
    i += 1
print(*D)
respStr = str(respJ)
print(respStr + FindOtvet(respI, respJ, totalSum))

Submission status: Wrong Answer

Solution code:
K = int(input())
q = [1,2,3,4,5,6,7,8,9]
for i in range(K-1):
    x, q = q[0], q[1:len(q)]
    print(x, end=" ")
    y = x % 10
    if y != 0:
        q.append(10*x+y-1)
    q.append(10*x+y)
    if y != 9:
        q.append(10*x+y+1)
print(q[0])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

from collections import deque

k = int(input())

que = deque(reversed([i for i in range(1, 10)]))

x = -1
for _ in range(k):
    # print(f"loop: {_}")
    # print(f"que: {que}")
    x = que.pop()
    # print(f"x: {x}\n")
    if x % 10 != 0:
        que.appendleft(x * 10 + x % 10 - 1)
    que.appendleft(x * 10 + x % 10)
    if x % 10 != 9:
        que.appendleft(x * 10 + x % 10 - 1)

print(x)

Submission status: Wrong Answer

Solution code:
q = [1,2,3,4,5,6,7,8,9]
for i in range(9999):
    x, q = q[0], q[1:len(q)]
#    print(x, end=" ")
    y = x % 10
    if y != 0:
        q.append(10*x+y-1)
    q.append(10*x+y)
    if y != 9:
        q.append(10*x+y+1)
print(q[0])

Submission status: Wrong Answer

Solution code:
import queue
k = int(input())
q = queue.Queue()

for i in range(1,10):
    q.put(i)

for i in range(k):
    x = q.get()

    p = 10 * x  
    m = x % 10
    if not p == 0:
        q.put(p + m - 1)

    q.put(p + m)

    if not p == 9:
        q.put(p + m + 1)
    
print(x)

Submission status: Wrong Answer

Solution code:
import numpy as np

k = int(input())


# ルンルン数で無くても二分探索を怖れない
def check(n):
    digits = []
    while n:
        n, m = divmod(n, 10)
        digits.append(m)
    digits.reverse()

    dp = np.zeros(10, dtype=np.int64)
    dp[1:digits[0]] = 1
    edge = digits[0]
    for d in digits[1:]:
        odp = dp.copy()
        dp[:-1] += odp[1:]
        dp[1:] += odp[:-1]
        dp[1:] += 1
        if edge != -1:
            if edge - 1 > d:
                edge = -1
            elif edge + 1 >= d:
                dp[edge - 1:d] += 1
                edge = d
            else:
                dp[max(0, edge - 1):edge + 2] += 1
                edge = -1
    result = dp.sum()
    if edge != -1:
        result += 1
    return result >= k


l = 0
r = 3234566667
while l + 1 < r:
    m = (l + r) // 2
    if check(m):
        r = m
    else:
        l = m
print(r)

Submission status: Wrong Answer

Solution code:
import sys
from decimal import *
K = int(input())
dp = []
count = 0
for i in range(9):
    dp.append(str(i+1))
    count = count + 1
    if count == K:
        print(dp[-1])
        sys.exit()
for j in range(10):
    print(j)
    for i in range(len(dp)):
        if len(dp[i]) == j+1:
            if int(dp[i][-1]) != 0 and int(dp[i][-1]) != 9:
                dp.append(str(Decimal(int(dp[i]))*Decimal(10)+Decimal(int(dp[i][-1]))-Decimal(1)))
                count = count + 1
                if count == K:
                    print(Decimal(int(dp[-1])))
                    sys.exit()
                dp.append(str(Decimal(int(dp[i]))*Decimal(10)+Decimal(int(dp[i][-1]))))
                count = count + 1
                if count == K:
                    print(dp[-1])
                    sys.exit()
                dp.append(str(Decimal(int(dp[i]))*Decimal(10)+Decimal(int(dp[i][-1]))+Decimal(1)))
                count = count + 1
                if count == K:
                    print(dp[-1])
                    sys.exit()
            elif int(dp[i][-1]) == 0:
                dp.append(str(Decimal(int(dp[i]))*Decimal(10)))
                count = count + 1
                if count == K:
                    print(dp[-1])
                    sys.exit()
                dp.append(str(Decimal(int(dp[i]))*Decimal(10)+Decimal(1)))
                count = count + 1
                if count == K:
                    print(dp[-1])
                    sys.exit()
            elif int(dp[i][-1]) == 9:
                dp.append(str(Decimal(int(dp[i]))*Decimal(10)+Decimal(int(dp[i][-1]))-Decimal(1)))
                count = count + 1
                if count == K:
                    print(dp[-1])
                    sys.exit()
                dp.append(str(Decimal(int(dp[i]))*Decimal(10)+Decimal(int(dp[i][-1]))))
                count = count + 1
                if count == K:
                    print(dp[-1])
                    sys.exit()
#print(dp[K-1])

Submission status: Wrong Answer

Solution code:
# k = int(input())
listA = [0,1,2,3,4,5,6,7,8,9]
k = int("15")
z = 10

q = k // z
mod = k % z
if q == 0:
    print(str(listA[mod - 1]))
else:
    print(str(q + 1)+ str(listA[mod - 2]))

# for i in range(k):

# print([1,2,3,4,5,6,7,8,9,10,11,12,21,22,23,24,25,26,27,28,29,210,211,212][int(input()) - 1])

Submission status: Wrong Answer

Solution code:
import numpy as np

k = int(input())


# ルンルン数で無くても二分探索を怖れない
def check(n):
    digits = []
    while n:
        n, m = divmod(n, 10)
        digits.append(m)
    digits.reverse()

    dp = np.zeros(10, dtype=np.int64)
    dp[1:digits[0]] = 1
    edge = digits[0]
    for d in digits[1:]:
        odp = dp.copy()
        dp[:-1] += odp[1:]
        dp[1:] += odp[:-1]
        dp[1:] += 1
        if edge != -1:
            if edge - 1 > d:
                edge = -1
            elif edge + 1 >= d:
                dp[edge - 1:d] += 1
                edge = d
            else:
                dp[edge - 1:edge + 2] += 1
                edge = -1
    result = dp.sum()
    if edge != -1:
        result += 1
    return result >= k


l = 0
r = 3234566667
while l + 1 < r:
    m = (l + r) // 2
    if check(m):
        r = m
    else:
        l = m
print(r)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

from collections import deque

k = int(input())

que = deque(reversed([i for i in range(1, 10)]))

for _ in range(k):
    # print(f"loop: {_}")
    # print(f"que: {que}")
    x = que.pop()
    # print(f"x: {x}\n")
    if x % 10 != 0:
        que.appendleft(10 * x - 1)
    que.appendleft(10 * x)
    if x % 10 != 9:
        que.appendleft(10 * x + 1)
    if _ == k - 1:
        print(x)

Submission status: Wrong Answer

Solution code:
from collections import deque

K = int(input())
Q = list(range(1, 10))

for i in range(K):
    x = Q[i]
    y = x%10
    if y != 0:
        Q.append(10*x + y-1)
    Q.append(10*x + y)
    if y != 9:
        Q.append(10*x + y+1)

print(Q[K])

Submission status: Wrong Answer

Solution code:
from collections import deque
k = int(input())
d = deque()
d += [1,2,3,4,5,6,7,8,9]
for i in range(k):
#     print(d, now)
    now = d.popleft()
    if now%10 != 0:
        d.append(10 * now + now % 10 - 1)
    d.append(10 * now + now % 10)
    if now%10 != 9:
        d.append(10 * now + now % 10 + 1)
print(k, now)

Submission status: Wrong Answer

Solution code:
K = int(input())
 
list = [1,2,3,4,5,6,7,8,9]
i = 0
while len(list) != 0:
    v = list.pop(0)
 
    i += 1
    if i == K:
        break
    t = v%10
    s = v*10
    if t == 0:
        list.append(s)
        list.append(s+1)
    elif v%10 == 9:
        list.append(s+8)
        list.append(s+9)
    else:
        list.append(v*11-1)
        list.append(v*11)
        list.append(v*11+1)
 
print(v)

Submission status: Wrong Answer

Solution code:
K = int(input())
a = [[1], [1, 2], [1, 2, 3], [2, 3, 4], [
    3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9]]
result = []
stack = list(range(0, 10))
i = -1
while len(result) < K:
    i += 1
    l = []
    for j in stack:
        for k in a[j // (10**i)]:
            l.append((10**(1+i))*k+j)

    result += stack[:]
    stack = l[:]
l = sorted(result)
print(l[K])

Submission status: Wrong Answer

Solution code:
K = int(input())
N = 10
l = [[0] * 10 for i in range(N)]

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

if K < 10:
    print(K)
else:
    remain = K - 9
    for i in range(1, N):
        for j in range(10):
            if j == 0:
                l[i][j] = 2 **(i - 1)
            else:
                if j == 9:
                     l[i][j] = l[i-1][j-1] + l[i-1][j]
                else:
                    l[i][j] = l[i-1][j-1] + l[i-1][j] + l[i-1][j+1]
                remain -= l[i][j]
            if remain <= 0:
                break
        if remain <= 0:
            break

    ans = j * (10 ** i)

    remain += l[i][j]
    print(i, j, remain)
    print(l)

    for k in range(i):
        i -= 1
        if j == 0:
            remain -= l[i][j]
            if remain <= 0:
                remain += l[i][j]
            else:
                j += 1
        elif j == 9:
            remain -= l[i][j-1]
            if remain <= 0:
                remain += l[i][j-1]
                j -= 1
        else:
            remain -= l[i][j-1]
            if remain <= 0:
                remain += l[i][j-1]
                j -= 1
            else:
                remain -= l[i][j]
                if remain <= 0:
                    remain += l[i][j]
                else:
                    remain += l[i][j+1]
                    j += 1
        print(j)
        ans += j * (10 ** i)

    print(ans)

Submission status: Wrong Answer

Solution code:
k = int(input())

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

for i in range(k):
    x = que[0]
    del que[0]
    if x%10 != 0:
        que.append(10*x+(x%10)-1)
    que.append(10*x+(x%10))
    if x%10 != 9:
        que.append(10*x+(x%10)+1)
    print(x)

Submission status: Wrong Answer

Solution code:
import queue
q = queue.Queue()
for i in range(1,10):
   q.put(i)

def k_th(q,k):
  for i in range(k):
      x=q.get()
      if x%10!=0:
        q.put(10*x-1)
      q.put(10*x)
      if x%10!=9:
        q.put(10*x+1)
  return x

K=int(input())
print(k_th(q,K))

Submission status: Wrong Answer

Solution code:
def jud(n1,n2):
	if abs(n1-int(str(n2)[0]))<=1:
		return 1
	else:
		return 0

rnrn = [[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]]

for div in range(1,10):
	rnrn.append([])
	for i in range(len(rnrn[div])):
		y = str(rnrn[div][i])
		x = int(y[-1])
		if x-1!=-1:
			rnrn[div+1].append(int(y+str(x-1)))
		rnrn[div+1].append(int(y+str(x)))
		if x+1!=10:
			rnrn[div+1].append(int(y+str(x+1)))
		
rnrn2 = []
for i in range(len(rnrn)):
	rnrn2.extend(rnrn[i])

print(rnrn2)

Submission status: Wrong Answer

Solution code:
import queue
q = queue.Queue()
for i in range(1,10):
   q.put(i)

def k_th(q,k):
  for i in range(k):
      x=q.get()
      if x%10!=0:
        q.put(10*x-1)
      q.put(10*x)
      if x%9!=0:
        q.put(10*x+1)
  return x

K=int(input())
print(k_th(q,K))

Submission status: Wrong Answer

Solution code:
from collections import deque
k=int(input())
q=deque(list(range(1, 10)))
ans,x,y,tmp=0,0,0,0
for i in range(k):
  ans=q.popleft()
  x,y=ans*10,ans%10
  tmp=10*x+y
  if y != 0:
    q.append(tmp-1)
  q.append(tmp)
  if y != 9:
    q.append(tmp+1)
print(ans)

Submission status: Wrong Answer

Solution code:
import queue

K = int(input())
A = queue.Queue()

for i in range(1, 10):
        A.put(i)

num = 0
while num < K:
        emp = A.get()
        var = emp % 10
        if var != 0:
                A.put(emp*10+var-1)
        A.put(10*emp)
        if var != 9:
                A.put(emp*10+var+1)
        num += 1

print(emp)

Submission status: Wrong Answer

Solution code:
import queue

K = int(input())
A = queue.Queue()

for i in range(1, 10):
        A.put(i)

num = 0
while num < K:
        emp = A.get()
        var = emp % 10
        if var != 0:
                A.put(emp*10+var-1)
        A.put(10*emp)
        if var != 9:
                A.put(emp*10+var+1)
        num += 1
        print(num, emp)

print(emp)

Submission status: Wrong Answer

Solution code:
import sys
from decimal import *
K = int(input())
dp = []
count = 0
for i in range(9):
    dp.append(str(i+1))
    count = count + 1
    if count == K:
        print(dp[-1])
        sys.exit()
for j in range(9):
    for i in range(len(dp)):
        if len(dp[i]) == j+1:
            if int(dp[i][-1]) != 0:
                dp.append(str(Decimal(int(dp[i]))*Decimal(10)+Decimal(int(dp[i][-1]))-Decimal(1)))
                count = count + 1
                if count == K:
                    print(Decimal(int(dp[-1])))
                    sys.exit()
                dp.append(str(Decimal(int(dp[i]))*Decimal(10)+Decimal(int(dp[i][-1]))))
                count = count + 1
                if count == K:
                    print(dp[-1])
                    sys.exit()
                dp.append(str(Decimal(int(dp[i]))*Decimal(10)+Decimal(int(dp[i][-1]))+Decimal(1)))
                count = count + 1
                if count == K:
                    print(dp[-1])
                    sys.exit()
            else:
                dp.append(str(Decimal(int(dp[i]))*Decimal(10)))
                count = count + 1
                if count == K:
                    print(dp[-1])
                    sys.exit()
                dp.append(str(Decimal(int(dp[i]))*Decimal(10)+Decimal(1)))
                count = count + 1
                if count == K:
                    print(dp[-1])
                    sys.exit()

Submission status: Wrong Answer

Solution code:
K = int(input())


from itertools import product
d = {}
num_list = []
for i in range(10):
    nums = set([min((i-1)%10, i), i, max((i+1)%10, i)])
#     nums = set([i, min(10-(i-1)%10, i),max((i+1)%10, i)])
    nums = [str(el) for el in nums]
    d[i] = list(product([str(i)], list(nums)))
    d[i] = [int(''.join(el)) for el in d[i]]
    d[i] = ['{:02}'.format(el) for el in d[i]]
    
    num_list.extend(d[i])
num_list = sorted(num_list)
dd = [None, None, d, 
      {i:[] for i in range(1,10)},
      {i:[] for i in range(1,10)},
      {i:[] for i in range(1,10)},
      {i:[] for i in range(1,10)},
      {i:[] for i in range(1,10)},
      {i:[] for i in range(1,10)},
      {i:[] for i in range(1,10)},
      {i:[] for i in range(1,10)},
      {i:[] for i in range(1,10)},
      {i:[] for i in range(1,10)},
      {i:[] for i in range(1,10)},
      {i:[] for i in range(1,10)},
      {i:[] for i in range(1,10)},
      {i:[] for i in range(1,10)},
      {i:[] for i in range(1,10)},
      {i:[] for i in range(1,10)},
      {i:[] for i in range(1,10)},
      {i:[] for i in range(1,10)},
      {i:[] for i in range(10)}]

def gen_2ll():
    count = 0
    ret = 0
    while int(ret)!=99:
        if int(ret)< 9 :
            ret += 1
            count += 1
            yield ret
        else:
            for i in range(1,10):
                for ret in d[i]:
                    count += 1
                    yield ret

ll2_list = list(gen_2ll())
                   
def get_digit_top_list(num_digit, top_num):
#     print(333, num_digit, top_num)
    if top_num == 0 and num_digit>2:
        lls = []
        for top_num in range(1,10):
            lls.extend(get_digit_top_list(num_digit-1,top_num ))
#             print(44444,lls)
        return ['0'+el for el in lls]
    ret = dd[num_digit][top_num]
    if ret:
        return ret

    second_nums = sorted(set([min((top_num-1)%10, top_num), top_num, max((top_num+1)%10, top_num)]))    
    for second_num in second_nums:
#         print(111,dd[num_digit][top_num])
        rem_nums = get_digit_top_list(num_digit-1, int(second_num))
        for rem_num in rem_nums:
            ll = str(top_num) + rem_num
            ret.append(ll)
    dd[num_digit][top_num] = ret

    
    return ret

def get_kth_ll(K):
    if K<=len(ll2_list):
        print(ll2_list[K-1])
    else:
        K -= len(ll2_list)
        for num_digit in range(3,100):
            for top_num in range(1,10):
                _ll_list = get_digit_top_list(num_digit, top_num)
#                 print(222, K, len(_ll_list))
                if K-len(_ll_list)<0:
                    print(sorted([int(el) for el in _ll_list])[K-1])
                    return None
                else:
                    K -= len(_ll_list)
get_kth_ll(K)

Submission status: Wrong Answer

Solution code:
K = int(input())
a = []
def dfs(x):
    if x > 3234566667:
        return
    a.append(x)
    for i in range(10):
        if abs(x%10-i) <= 1:
            dfs(x*10+i)

for i in range(1,11):
    dfs(i)
a = sorted(a)
print(a[K-1])