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: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	k = int(input())
	#b , c = tin()
	#s = input()
	l=['_']*50
	l[0]=0
	for _ in range(k):
		for i, v in enumerate(l):
			l[i]+=1
			if l[i] == 10 and l[i+1]=='_':
				l[i+1]=1
				l[:i+1]=[0]*(i+1)
				break
			elif l[i] == 10:
				l[i]=l[i+1]
			elif l[i+1]=='_':
				#l[:i]=[l[i]-1]*(i)
				for j in range(1,i+1):
					l[i-j]=max(0, l[i-j+1]-1)
				break				
			elif l[i] <= l[i+1]+1:
				#l[:i]=[l[i]-1]*i
				for j in range(1,i+1):
					l[i-j]=max(0, l[i-j+1]-1)
				break	
		#print(*l)
		
	print(''.join([str(c) for c in l[::-1] if c != '_']))
				
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
k = int(input())
lunlun = []
def dfs(A):
    if len(A) == 10:
        return
    else:
        start = int(A[-1])
        if start == 9:
            for i in range(start-1, start+1):
                A.append(str(i))
                lunlun.append("".join(A))
                dfs(A)
                A.pop()
        elif start == 0:
            for i in range(start, start+2):
                A.append(str(i))
                lunlun.append("".join(A))
                dfs(A)
                A.pop()
        else:
            for i in range(start-1, start+2):
                A.append(str(i))
                lunlun.append("".join(A))
                dfs(A)
                A.pop()
for j in range(1, 10):
    lunlun.append(str(j))
    dfs([str(j)])
lunlun = list(map(int, lunlun))
lunlun.sort()
print(lunlun[k-1])

Submission status: Accepted

Solution code:
k = int(input())
lun = [str(i) for i in range(1, 10)]
L = [str(i) for i in range(1, 10)]
nL = []
while len(lun) < 10 ** 5:
    for num in L:
        l = num[-1]
        lm = int(l) - 1
        lp = int(l) + 1
        nL.append(num + l)
        if lm >= 0:
            nL.append(num + str(lm))
        if lp < 10:
            nL.append(num + str(lp))
    lun.extend(nL)
    L = nL
    nL = []
lunlun = [int(x) for x in lun]
lunlun.sort()
print(lunlun[k-1])

Submission status: Accepted

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    k = int(ipt())
    q = queue.Queue()
    for i in range(1,10):
        q.put(i)
    for _ in [0]*k:
        qi = q.get()
        if not qi%10 == 0:
            q.put(qi*10+qi%10-1)
        q.put(qi*10+qi%10)
        if not qi%10 == 9:
            q.put(qi*10+qi%10+1)
    print(qi)
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque

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

cnt = 0
while q:
    curr = q.popleft()
    cnt += 1
    if cnt == k:
        break
    if curr % 10 == 9:
        q.append(curr * 10 + curr % 10 - 1)
        q.append(curr * 10 + curr % 10)
    elif curr % 10 == 0:
        q.append(curr * 10 + curr % 10)
        q.append(curr * 10 + curr % 10 + 1)
    else:
        q.append(curr * 10 + curr % 10 - 1)
        q.append(curr * 10 + curr % 10)
        q.append(curr * 10 + curr % 10 + 1)

print(curr)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N = getN()

next = [
[0, 1],
[0, 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]
]

ans = []

def dfs(s):
    global ans
    if len(s) >= 11:
        return
    # 上限を超えない範囲で実行
    else:
        ans.append(int(s))
        # dfs
        s_last = int(s[-1])
        for i in next[s_last]:
            dfs(s + str(i))

# 始点は1~9
for i in range(1, 10):
    dfs(str(i))

ans.sort()
print(ans[N - 1])

Submission status: Accepted

Solution code:
def expand(x):
  s = x[0]
  if (s == '0'):
    e = ['0', '1']
  elif (s == '9'):
    e = ['8', '9']
  else:
    e = [str(int(s) + (i-1)) for i in range(3)]
  y = [i+x for i in e]
  return y


Y      = [str(i) for i in range(10)]
result = Y.copy()

for _ in range(10):
  tmp = []
  for i in Y:
    tmp += expand(i)
  result.extend(tmp)
  Y = tmp
  
iY = set(map(int, result))
iY = sorted(list(iY))

X = int(input())
print(iY[X])

Submission status: Accepted

Solution code:
K = int(input())

lst = [i for i in range(1, 10)]

if K < 10:
    print(K)
else:
    now = 0
    K -= 9
    ans = 0
    while True:
        md = lst[now] % 10
        for i in range(10):
            if abs(md - i) <= 1:
                K -= 1
                ans = lst[now] * 10 + i
                lst.append(ans)
                if K == 0:
                    print(ans)
                    exit()
        now += 1

Submission status: Accepted

Solution code:
K=int(input())
ans=[]
def saiki(A):
    genzai_saigo=int(A[-1])
    ketasu=len(A)
    if ketasu>0:
        B="".join(A)
        ans.append(eval(B))
    if ketasu==10:
        return
    for i in [genzai_saigo-1,genzai_saigo,genzai_saigo+1]:
        if i < 0 or i>9:
            continue
        A.append(str(i))
        saiki(A)
        A.pop()
for i in range(1,10):
    saiki([str(i)])
ans.sort()
print(ans[K-1])

Submission status: Accepted

Solution code:
from sys import stdin
from collections import deque
def main():
    #入力
    readline=stdin.readline
    k=int(readline())

    lunlun_number=[]
    d=deque(map(str,range(1,10)))
    cnt=0
    while cnt<k:
        now=d.popleft()
        lunlun_number.append(now)
        cnt+=1
        if now[-1]=="0":
            nex=("0","1")
        elif now[-1]=="9":
            nex=("8","9")
        else:
            last=int(now[-1])
            nex=(str(last-1),str(last),str(last+1))
        for x in nex:
            d.append(now+x)

    print(lunlun_number[k-1])

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
k = int(input())

L = list(range(10))
i = 1
while len(L) <= k:
    Li = L[i]
    a = Li % 10
    for b in range(a - 1, a + 2):
        if b < 0 or b > 9:
            continue
        L.append(Li * 10 + b)
    i += 1

print(L[k])

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

if __name__ == "__main__":
    k = int(input())
    q = collections.deque([])
    for i in range(1,10):
        q.append(i)
    for i in range(k-1):
        x = q.popleft()
        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.popleft())

Submission status: Accepted

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

if K < 10:
    print(K)
    exit()

q = collections.deque()
for i in range(1, 10):
    q.append(i)
i = 9
while True:
    x = q.popleft()
    lsk = x % 10
    shifted = x * 10
    if lsk != 0:
        q.append(shifted + lsk - 1)
        i += 1
        if i == K:
            print(shifted + lsk - 1)
            break
    q.append(shifted + lsk)
    i += 1
    if i == K:
        print(shifted + lsk)
        break
    if lsk != 9:
        q.append(shifted + lsk + 1)
        i += 1
        if i == K:
            print(shifted + lsk + 1)
            break

Submission status: Accepted

Solution code:
from collections import deque


k = int(input())
num_deq = deque([i for i in range(1, 10)])
for i in range(k-1):
    x = num_deq.popleft()
    if x % 10 != 0:
        num_deq.append(10 * x + x % 10 - 1)
    num_deq.append(10 * x + x % 10)
    if x % 10 != 9:
        num_deq.append(10 * x + x % 10 + 1)
x = num_deq.popleft()
print(x)

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

k = int(input())


import queue
q = queue.Queue()

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

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

total = 9
while total <= k:
    x = q.get()
    if x % 10 != 0:
        val = x * 10 + x % 10 - 1
        q.put(val)
        total += 1
        if total == k:
            print(val)
            exit()

    val = x * 10 + x % 10
    q.put(val)
    total += 1
    if total == k:
        print(val)
        exit()
    if x % 10 < 9:
        val = x * 10 + x % 10 + 1
        q.put(val)
        total += 1
        if total == k:
            print(val)
            exit()
    
    if total >= k:
        for i in range(total - k):
            q.get()
        print(q.get())
        exit()

Submission status: Accepted

Solution code:
from collections import deque
n = int(input())
L = list(range(1, 10))
count = 9
d = deque([1,2,3,4,5,6,7,8,9])
while count < n:
    p = d.popleft()
    p1 = p%10
    if p1 == 0:
        lunlun = p*10 + p1
        d.append(lunlun)
        L.append(lunlun)
        count += 1
        lunlun += 1
        d.append(lunlun)
        L.append(lunlun)
        count += 1
    elif p1 == 9:
        lunlun = p*10 + p1 - 1
        d.append(lunlun)
        L.append(lunlun)
        count += 1
        lunlun += 1
        d.append(lunlun)
        L.append(lunlun)
        count += 1
    else:
        lunlun = p*10 + p1 - 1
        d.append(lunlun)
        L.append(lunlun)
        count += 1
        lunlun += 1
        d.append(lunlun)
        L.append(lunlun)
        count += 1
        lunlun += 1
        d.append(lunlun)
        L.append(lunlun)
        count += 1
print(L[n-1])

Submission status: Accepted

Solution code:
from collections import deque

k = int(input())
q = deque([])
for i in range(1, 10):
    q.append(i)

cnt = 0
while cnt < k:
    s = q.popleft()
    cnt += 1
    t = s % 10
    if t != 0:
        q.append(10 * s + (t - 1))
    q.append(10 * s + t)
    if t != 9:
        q.append(10 * s + (t + 1))
    
print(s)

Submission status: Accepted

Solution code:
import numpy as np
import math
import collections
import fractions
import itertools

def rec(d, val, all):
    all.append(val)
    if d >= 10:
        return
    for j in range(-1, 2):
        add = val % 10 + j
        if add >= 0 and add <= 9:
            rec(d+1, val*10+add, all)

def solve():
    k = int(input())
    all = []
    for i in range(1,10):
        rec(1, i, all)
    all.sort()
    print(all[k-1])
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from collections import deque
K = int(input())
d = deque(["1","2","3","4","5","6","7","8","9"])
ans = 0
for i in range(K):
    now = d.popleft()
    num = int(now[-1])
    if num == 0:
        d.append(now+"0")
        d.append(now+"1")
    elif num == 9:
        d.append(now+"8")
        d.append(now+"9")
    else:
        d.append(now+str(num-1))
        d.append(now+str(num))
        d.append(now+str(num+1))
print(now)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

K = int(input())

# indexは桁数
luns = [[]]
luns.append(list("123456789"))
for keta in range(2, 11):
    keta_lun = []
    for s in luns[-1]:
        lst = int(s[-1])
        if lst - 1 >= 0:
            keta_lun.append(s + str(lst - 1))
        keta_lun.append(s + str(lst))
        if lst + 1 < 10:
            keta_lun.append(s + str(lst + 1))
    luns.append(keta_lun)

index = 0
for keta_luns in luns:
    for lun in keta_luns:
        index += 1
        if index == K:
            print(lun)
            quit()

Submission status: Accepted

Solution code:
# 解説を参考に作成
from collections import deque


def solve(K):
    lunlun = deque([i for i in range(1, 10)])

    ans = 0
    for _ in range(K):
        ans = lunlun.popleft()
        x = ans * 10 + ans % 10
        if x % 10 != 0:
            lunlun.append(x - 1)
        lunlun.append(x)
        if x % 10 != 9:
            lunlun.append(x + 1)

    print(ans)


if __name__ == '__main__':
    K = int(input())
    solve(K)

Submission status: Accepted

Solution code:
def solve(K):
    lun = [0]

    def nextLunlun(arr, d=0):
        arr[d] += 1
        if arr[d] == 10:
            if d + 1 == len(arr):
                arr.append(1)
                arr[d] = 0
                return arr
            else:
                arr = nextLunlun(arr, d + 1)
                arr[d] = arr[d + 1] - 1 if arr[d + 1] > 0 else 0
                return arr
        if d + 1 != len(arr):
            if abs(arr[d] - arr[d + 1]) > 1:
                if arr[d] < arr[d + 1]:
                    arr[d] = arr[d + 1] - 1
                    return arr
                else:
                    arr = nextLunlun(arr, d + 1)
                    arr[d] = arr[d + 1] - 1 if arr[d + 1] > 0 else 0
                    return arr
        return arr

    for _ in range(K):
        lun = nextLunlun(lun)

    ans = 0
    for i in range(len(lun)):
        ans += lun[i] * (10 ** i)

    print(ans)


if __name__ == '__main__':
    K = int(input())
    solve(K)

Submission status: Accepted

Solution code:
from collections import deque
q=deque([1,2,3,4,5,6,7,8,9])
K=int(input())
for i in range(K-1):
  x=q.popleft()
  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.popleft())

Submission status: Accepted

Solution code:
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

'''
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,100 (36)
101,110,111,112,121,122,123,210,211,212,221,222,223,232,233,234,

1
10
11
12
100
101
110
111
112
121
122
123
1000
1001
1002


'''
#precomp:
nums = []
def precomp(i):
    temp = str(i)
    x=[-1,0,1]
    for j in range(3):
        foo = int(temp[-1])+x[j]
        if(foo>=0 and foo<=9):
            toadd = int(temp+str(foo))

            if (i > 3234566667):
                return
            nums.append(toadd)
            precomp(toadd)

for i in range(1, 10):
    nums.append(i)
    precomp(i)

nums.sort()

k = INT()

print(nums[k-1])

# k = INT()

Submission status: Accepted

Solution code:
from collections import deque
que=deque([i for i in range(1,10)])
k=int(input())
count=0
while count!=k:
  a=que.popleft()
  count+=1
  if a%10==9:
    que.extend([10*a+8,10*a+9])
  elif a%10==0:
    que.extend([10*a,10*a+1])
  else:
    b=a*10+(a%10)-1
    que.extend([b,b+1,b+2])
print(a)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

K = int(readline())

from collections import deque
q = deque([i for i in range(1,10)])

cnt = 0
while q:
  n = q.popleft()
  cnt += 1
  if cnt == K:
    print(n)
    break
  right = n % 10
  for c in range(max(right - 1, 0),min(right + 2,10)):
    q.append(n * 10 + c)

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from heapq import heapify, heappop, heappush
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

# ここから書き始める
k = int(input())
queue = deque([str(i) for i in range(1, 10)])
ans = ""
for i in range(k):
    ans = queue.popleft() 
    if ans[-1] != "0":
        queue.append(ans + str(int(ans[-1]) - 1))
    queue.append(ans + ans[-1])
    if ans[-1] != "9":
        queue.append(ans + str(int(ans[-1]) + 1))
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
k = int(input())
d = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

for i in range(k - 1):
    x = d.popleft()
    if x%10 > 0:
        d.append(x*10 + x%10 - 1)
    d.append(x*10 + x%10)
    if x%10 < 9:
        d.append(x*10 + x%10 + 1)

print(d.popleft())

Submission status: Accepted

Solution code:
k = int(input())
lis = [i for i in range(1,10)]
tmp = [i for i in range(1,10)]
while len(lis)<k+1:
    tmp2 = []
    for i in tmp:
        la = i%10
        if la==0:
            tmp2.append(i*10)
            tmp2.append(i*10+la+1)
        elif la==9:
            tmp2.append(i*10+la)
            tmp2.append(i*10+la-1)
        else:
            tmp2.append(i*10+la-1)
            tmp2.append(i*10+la)
            tmp2.append(i*10+la+1)
    lis.extend(tmp2)
    tmp = [i for i in tmp2]

lis.sort()
#print(lis)
print(lis[k-1])

Submission status: Accepted

Solution code:
# D - Lunlun Number
from collections import deque
K = int(input())
lun = deque([1,2,3,4,5,6,7,8,9])
for i in range(K-1):
    x = lun.popleft()
    if x%10>0:
        lun.append(10*x+x%10-1)
    lun.append(10*x+x%10)
    if x%10<9:
        lun.append(10*x+x%10+1)
print(lun.popleft())

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')


#import numpy as np

from collections import deque

def main():
	k=II()

	Q=deque()
	for i in range(1,10):
		Q.append(i)

	for i in range(k-1):
		x=Q.popleft()

		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[0])














if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
from queue import deque

k=int(input())
q=deque()
for i in range(1,10):
    q.append(i)

for i in range(k):
    x=q.popleft()
    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(x)

Submission status: Accepted

Solution code:
from queue import deque

k = int(input())
que = deque()
for i in range(1,10):
    que.append(i)

for i in range(k):
    if i == (k-1):
        print(que.popleft())
        exit()
    now = que.popleft()
    if now%10 != 0:
        que.append(now*10+now%10-1)
    que.append(now*10+now%10)
    if now%10 != 9:
        que.append(now*10+now%10+1)

Submission status: Accepted

Solution code:
from collections import deque
k=int(input())
queue=deque(range(1,10))
x=0
for _ in range(k):
  x=queue.popleft()
  if not x%10==0:
    queue.append(10*x+(x%10)-1)
  queue.append(10*x+(x%10))
  if not x%10==9:
    queue.append(10*x+(x%10)+1)
print(x)