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: Time Limit Exceeded

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())

cnt = [[str(i)] for i in range(10)]

d = 2
# from functools import reduce
total = 9
while total < 10 ** 5:
    new_cnt = [[] for i in range(10)]
    for i in range(10):
        if i - 1 >= 0:
            new_cnt[i].append(str(i) + cnt[i - 1][-1])
        if i + 1 < 10:
            new_cnt[i].append(str(i) + cnt[i + 1][-1])
        new_cnt[i].append(str(i) + cnt[i][-1])

        if i != 0:
            total += len(new_cnt[i])
    for i in range(10):
        cnt[i] += new_cnt[i]

ans = sorted(map(int, sum(cnt[1:10], [])))
print(ans[k - 1])

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

print(n)

Submission status: Time Limit Exceeded

Solution code:
# D - Lunlun Number
K = int(input())
lun = [1,2,3,4,5,6,7,8,9]
for i in range(K-1):
    x = lun.pop(0)
    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.pop(0))

Submission status: Time Limit Exceeded

Solution code:
k=int(input())

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

for i in range(k):
    x=queue.pop(0)
    if (x%10!=0):
        queue.append(10*x+(x%10)-1)
    queue.append(10*x+(x%10))
    if (x%10!=9):
        queue.append(10*x+(x%10)+1)
        
print(x)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
cnt = 0
i = 0
while cnt < K:
    i += 1
    NUM = str(i)
    if len(NUM) == 1:
        cnt += 1
        continue
    for j in range(1,len(NUM)):
        if abs(int(NUM[j]) - int(NUM[j-1])) > 1:
            break
        if j == len(NUM) - 1:
            cnt += 1
print(i)

Submission status: Time Limit Exceeded

Solution code:
_input = input
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

#ここに書きたいコードを書く
#データ読み込み
K=int(input())

bansu=10
n=9

if K <= 10:
	print(K)

while bansu <= K:
	n += 1
	n_str = str(n)
	l=len(n_str)
	lun_flag = True
	for i in range(l-1):
		if abs(int(n_str[i]) - int(n_str[i+1])) >     1:
			lun_flag = False
	
	#print(n,bansu,lun_flag)
	
	if lun_flag == True:
		bansu += 1

if K > 10:
	print(n)

input = _input

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
K = 100000
a = b = c = d = e = f = 1
g = 0
h = deque()
for i in range(1, int(K)):
  for a in range(0, 9):
    for b in range(0, 9):
      for c in range(0, 9):
        for d in range(0, 9):
          for e in range(0, 9):
            for f in range(0, 9):
              i = a * 100000 + b * 10000 + c * 1000 + d * 100 + e * 10 + f * 1
              if 'g' in 'i':
                break
              if abs(a - b) <= 1 and abs(b - c) <= 1 and abs(c - d) <= 1 and abs(d - e) <= 1 and abs(e - f) <= 1:
                h.append(i)

j = int(input())
print (h[j])

Submission status: Time Limit Exceeded

Solution code:
K = 100000
a = b = c = d = e = f = 1
g = 0
h = []
for i in range(1, int(K)):
  for a in range(0, 9):
    for b in range(0, 9):
      for c in range(0, 9):
        for d in range(0, 9):
          for e in range(0, 9):
            for f in range(0, 9):
              i = a * 100000 + b * 10000 + c * 1000 + d * 100 + e * 10 + f * 1
              if 'g' in 'i':
                break
              if abs(a - b) <= 1 and abs(b - c) <= 1 and abs(c - d) <= 1 and abs(d - e) <= 1 and abs(e - f) <= 1:
                h.append(i)

j = int(input())
print (h[j + 1])

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

k = int(input())
limit = 10#最大桁数

start = [i for i in range(1, 10)]#最初にスタートする数
ans = []
q=deque(start)
while q:
	num=q.popleft()
	if len(str(num))>11:#処理終了
		continue#次のQへ
	ans.append(num)
	last=str(num)[-1]
	if last == "0":
		add = ['0', '1']
	elif last == '9':
		add = ['8',"9"] 
	else:
		add = [str(int(last) - 1), str(int(last)), str(int(last) + 1)]
	for i in add:
		q.append(int(str(num)+i))

ans = sorted(ans)
print(ans[k - 1])#k番目の答えを創出

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
ANS=[]
for i in range(1,10**5):
  LEN=len(str(i))
  STR=str(i)
  if LEN==1:
    ANS+=[i]
  for k in range(LEN-1):
    if abs(int(STR[k])-int(STR[k+1]))>1:
      break
    if k==LEN-2:
      ANS+=[i]
i=10**5
while i<10**7:
  LEN=len(str(i))
  STR=str(i)
  if LEN==1:
    ANS+=[i]
  for k in range(LEN-1):
    if abs(int(STR[k])-int(STR[k+1]))>1:
      i+=10*(LEN-(k+2))
      break
    if k==LEN-2:
      ANS+=[i]
ans=ANS[K-1] 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
ANS=[]
for i in range(1,10**6*2):
  LEN=len(str(i))
  STR=str(i)
  if LEN==1:
    ANS+=[i]
  for k in range(LEN-1):
    if abs(int(STR[k])-int(STR[k+1]))>1:
      break
    if k==LEN-2:
      ANS+=[i]
ans=ANS[K-1] 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
ANS=[]
for i in range(1,10**6*3):
  LEN=len(str(i))
  STR=str(i)
  if LEN==1:
    ANS+=[i]
  for k in range(LEN-1):
    if abs(int(STR[k])-int(STR[k+1]))>1:
      break
    if k==LEN-2:
      ANS+=[i]
ans=ANS[K-1] 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
ANS=[]
for i in range(1,10**6*5):
  LEN=len(str(i))
  STR=str(i)
  if LEN==1:
    ANS+=[i]
  for k in range(LEN-1):
    if abs(int(STR[k])-int(STR[k+1]))>1:
      break
    if k==LEN-2:
      ANS+=[i]
ans=ANS[K-1] 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
queue = [1, 2, 3, 4, 5, 6, 7, 8, 9]
n = 1
while n < k:
    a = queue.pop(0)
    b = a%10
    a *= 10
    if b in [1, 2, 3, 4, 5, 6, 7, 8]:
        queue += [a + b - 1, a + b, a + b + 1]
    elif b == 9:
        queue.append(a + 8)
        queue.append(a + 9)
    else:
        queue.append(a)
        queue.append(a + 1)
    n += 1
print(queue[0])

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
queue = [1, 2, 3, 4, 5, 6, 7, 8, 9]
n = 1
while n < k:
    a = queue.pop(0)
    b = a%10
    a *= 10
    if b == 0:
        queue.append(a)
        queue.append(a + 1)
    elif b == 9:
        queue.append(a + 8)
        queue.append(a + 9)
    else:
        queue.append(a + b - 1)
        queue.append(a + b)
        queue.append(a + b + 1)
    n += 1
print(queue[0])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-


def is_lunlun_number(a):

    A = str(a)
    n = len(A)

    if n == 1:
        return True

    for m in range(n - 1):
        if abs(int(A[m]) - int(A[m + 1])) > 1:  # 隣の桁との差が1より大きいと終了
            return False
    return True


K = int(input())
a = 1
j = 0

while j <= K - 1:  # K番目のルンルン数が見つかるまで

    if (is_lunlun_number(a)):
        j = j + 1
    a = a + 1  # 次の数字の検証

print(a - 1)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-


def is_lunlun_number(A):
    n = len(A)

    if n == 1:
        return True

    for m in range(n - 1):
        if abs(int(A[m]) - int(A[m + 1])) > 1:  # 隣の桁との差が1より大きいと終了
            return False
    return True


K = int(input())
a = 1
j = 0

while j <= K - 1:  # K番目のルンルン数が見つかるまで
    A = str(a)
    n = len(A)

    if (is_lunlun_number(A)):
        j = j + 1
    a = a + 1  # 次の数字の検証

print(a - 1)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
a=1
j=0

while j <= K - 1: #K番目のルンルン数が見つかるまで
    A=str(a)
    n=len(A) 
    if n==1: #aが1桁の場合,ルンルン数
        j=j+1
    else: #aが1桁でない場合、上の位から検証
        m = 0
        lunlun = True
        while m<n-1:
            if abs(int(A[m])-int(A[m+1]))>1: #隣の桁との差が1より大きいと終了
                lunlun=False
                break
            else:
                m=m+1
        if lunlun:
            j=j+1
    a=a+1 #次の数字の検証

print(a-1)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
ans=0
runrun = 0
i =1
while runrun < K:
    if i < 10:
        runrun +=1
        ans = i
    else:
        a = list(map(int,str(i)))
        for j in range(1,len(a)):
            tmp = 0
            if abs(a[j]-a[j-1])<=1:
                tmp +=1
        if tmp == len(a)-1:
            runrun +=1
            ans = i 
    i +=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())

runrun=[[1,2,3,4,5,6,7,8,9],[]]
count=9
keta=2
end=False
ans=-1

if x<=9:
    print(x)

while True:
    if end:
        break

    for ini in runrun[keta-2]:

        if ini%10==0:
            runrun[keta-1].append(ini*10)
            count+=1
            if count==x:
                end=True
                ans=ini*10
                break
            runrun[keta-1].append(ini*10+1)
            count+=1
            if count==x:
                end=True
                ans=ini*10+1
                break

        elif ini%10==9:
            runrun[keta-1].append(ini*10+8)
            count+=1
            if count==x:
                end=True
                ans=ini*10+8
                break
            runrun[keta-1].append(ini*10+9)
            count+=1
            if count==x:
                end=True
                ans=ini*10+9
                break

        else:
            runrun[keta-1].append(ini*10+ini%10-1)
            count+=1
            if count==x:
                end=True
                ans=ini*10+ini%10-1
                break
            runrun[keta-1].append(ini*10+ini%10)
            count+=1
            if count==x:
                end=True
                ans=ini*10+ini%10
                break
            runrun[keta-1].append(ini*10+ini%10+1)
            count+=1
            if count==x:
                end=True
                ans=ini*10+ini%10+1
                break

    keta +=1
    runrun.append([])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())

runrun=[[1,2,3,4,5,6,7,8,9],[]]
count=9
keta=2
end=False
ans=-1

while True:
    if end:
        break

    for ini in runrun[keta-2]:

        if ini%10==0:
            runrun[keta-1].append(ini*10)
            count+=1
            if count==x:
                end=True
                ans=ini*10
                break
            runrun[keta-1].append(ini*10+1)
            count+=1
            if count==x:
                end=True
                ans=ini*10+1
                break

        elif ini%10==9:
            runrun[keta-1].append(ini*10+8)
            count+=1
            if count==x:
                end=True
                ans=ini*10+8
                break
            runrun[keta-1].append(ini*10+9)
            count+=1
            if count==x:
                end=True
                ans=ini*10+9
                break

        else:
            runrun[keta-1].append(ini*10+ini%10-1)
            count+=1
            if count==x:
                end=True
                ans=ini*10+ini%10-1
                break
            runrun[keta-1].append(ini*10+ini%10)
            count+=1
            if count==x:
                end=True
                ans=ini*10+ini%10
                break
            runrun[keta-1].append(ini*10+ini%10+1)
            count+=1
            if count==x:
                end=True
                ans=ini*10+ini%10+1
                break

    keta +=1
    runrun.append([])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
q = list(range(1, 10))
i = 0

while i < k:
    i += 1

    org = q.pop(0)
    x = org % 10

    if x != 0:
        q.append(10 * org + x - 1)

    q.append( 10 * org + x)

    if x != 9:
        q.append(10 * org + x + 1)
print(org)

Submission status: Time Limit Exceeded

Solution code:

k = int(input())
q = list(map(str, range(1, 10)))
i = 0

while i < k:
    i += 1

    org = q.pop(0)
    x = int(org[-1])

    if x != 0:
        q.append(org + str(x- 1))

    q.append(org + str(x))

    if x != 9:
        q.append(org + str(x + 1))
print(org)

Submission status: Time Limit Exceeded

Solution code:
def jadge(K):
    l = []
    flag = True
    for k in str(K):
        l.append(int(k))
    for i in range(len(l)-1):
        if abs(l[i+1]-l[i]) > 1:
            flag = False
            return flag
            break
    if flag == True:
        return flag

K = str(input())
l = []
i = 0
while len(l) < int(K):
    i += 1 
    k = jadge(i)
    if k == True:
        l.append(i)
    
print(i)

Submission status: Time Limit Exceeded

Solution code:
def function(n):
  string = str(n)
  for i in range(len(string) - 1):
    if int(string[i]) - int(string[i + 1]) > 1:
      return i + 1
    elif int(string[i + 1]) - int(string[i]) > 1:
      return i
  return -1
 
k = int(input())
ans = []
n = 1
while len(ans) < k:
  m = function(n)
  if m == -1:
    ans.append(n)
    n += 1
  else:
    n = n + 10 ** (len(str(n)) - m - 1) - n % (10 ** (len(str(n)) - m - 1))
print(ans[-1])

Submission status: Time Limit Exceeded

Solution code:
def function(n):
  string = str(n)
  for i in range(len(string) - 1):
    if abs(int(string[i]) - int(string[i + 1])) > 1:
      return False
  return True

k = int(input())
ans = []
n = 1
while len(ans) < k:
  if function(n):
    ans.append(n)
  n += 1

print(ans[-1])

Submission status: Time Limit Exceeded

Solution code:
def isLunLun(num):
  pre = num%10
  while num != 0:
    num, mod = divmod(num, 10)
    if abs(mod-pre) > 1:
      return False
    pre = mod
  return True

K=int(input())
k=0
num = 1
latestLunLun = 0
while k != K:
  if isLunLun(num):
    k+=1
    latestLunLun = num
  num+=1
print(latestLunLun)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
queue = [1, 2, 3, 4, 5, 6, 7, 8, 9]

for i in range(k):
    a = queue.pop(0)
    if a % 10 != 0:
        queue.append(10*a + (a % 10) - 1)
    queue.append(10 * a + (a % 10))
    if a % 10 != 9:
        queue.append(10 * a + (a % 10) + 1)

print(a)

Submission status: Time Limit Exceeded

Solution code:
cur = []

def recur(n):
    if n > 10 ** 18:
        return
    cur.append(n)
    for i in range(10):
        if abs(n % 10 - i) <= 1:
            recur(10 * n + i)

for i in range(1, 10):
    recur(i)
cur.sort()
n = int(input())
print((cur[n - 1]))

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

if k <= 10:
  print(k)
else:
  m = 10
  count = 10
  while count <=k-1:
    m += 1
    if all([ abs(int(str(m)[i+1])-int(str(m)[i]))<=1  for i in range(len(str(m))-1)]):
      count += 1
    else:
      count += 0
  print(m)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
def lunlun_check(x):
    li =[]
    for i in range(len(str(x))):
        li.append(int(x/(10**i))%10)
    li.reverse()
    for i in range(1,len(li)):
        if abs(li[i]-li[i-1]) >= 2:
            return False
            break
    return True
cnt = 0
num = 1
while cnt < k:
    if lunlun_check(num):
        cnt = cnt + 1
    p = len(str(num))
    if not lunlun_check(int(num/(10**(p-2)))) and p >= 3:
        num = num + 10**(p-2)
    else:
        num = num + 1
print(num-1)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
k = int(input())
L = [1,2,3,4,5,6,7,8,9]
L = deque(L)
i = 0
while i < k:
    if int(str(L[i])[-1]) == 0:
        n2 = L[i]*10 + L[i]%10
        n3 = L[i]*10 + L[i]%10 +1
        L.append(n2)
        L.append(n3)
    elif 1 <= int(str(L[i])[-1]) <= 8:
        n1 = L[i]*10 + L[i]%10 -1
        n2 = L[i]*10 + L[i]%10
        n3 = L[i]*10 + L[i]%10 +1
        L.append(n1)
        L.append(n2)
        L.append(n3)
    elif int(str(L[i])[-1]) == 9:
        n1 = L[i]*10 + L[i]%10 -1
        n2 = L[i]*10 + L[i]%10
        L.append(n1)
        L.append(n2)
    i +=1

print(L[k-1])

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
def lunlun_check(x):
    li =[]
    for i in range(len(str(x))):
        li.append(int(x/(10**i))%10)
    li.reverse()
    for i in range(1,len(li)):
        if abs(li[i]-li[i-1]) >= 2:
            return False
            break
    return True
cnt = 0
num = 1
while cnt < k:
    if lunlun_check(num):
        cnt = cnt + 1
    p = len(str(num))
    if abs((int(num/(10**(p-1)))%10) - (int(num/(10**(p-2)))%10)) >= 2 and p >= 2:
        num = num + 10**(p-2)
    else:
        num = num + 1
print(num-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
def lunlun_check(x):
    li =[]
    for i in range(len(str(x))):
        li.append(int(x/(10**i))%10)
    li.reverse()
    for i in range(1,len(li)):
        if abs(li[i]-li[i-1]) >= 2:
            return False
            break
    return True
cnt = 0
num = 1
while cnt < k:
    if lunlun_check(num):
        cnt = cnt + 1
    num = num + 1
print(num-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
def lunlun_check(x):
    li =[]
    out =True
    for i in range(len(str(x))):
        li.append(int(x/(10**i))%10)
    li.reverse()
    for i in range(1,len(li)):
        if abs(li[i]-li[i-1]) >= 2:
            out = False
    return out

cnt = 0
num = 1
while cnt < k:
    if lunlun_check(num):
        cnt = cnt + 1
    num = num + 1
print(num-1)

Submission status: Time Limit Exceeded

Solution code:
import math
import copy
from queue import Queue

n = int(input())
#n, k = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#num = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
# s = [input() for i in range(n)]
#s = input()
# list = list(s)
# dp = [[0 for _ in range(2)] for _ in range(13)]
#s = [input() for i in range(n)]

#a = [[0 for _ in range(n+1)] for _ in range(n+1)]
#b = [[0 for _ in range(n+1)] for _ in range(n+1)]

queue = Queue()
temp = 0

if (n < 10):
    print(n)
else:
    for i in range(1,10):
        queue.put(i)
    for i in range(1,n):
        temp = queue.get()
        if (temp % 10 != 0) :
            queue.put(10 * temp + (temp % 10) - 1)
        queue.put(10 * temp + (temp % 10))
        if (temp % 10 != 9) :
            queue.put(10 * temp + (temp % 10) + 1)

print(queue.get())

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

def main():
    K = int(input())
    if K <= 9:
        print(K)

    que = deque(range(1,10))
    # print(que)
    cnt = 9
    while True:
        x = que.popleft()
        mod = x % 10

        if mod != 0:
            que.append(10 * x + mod - 1)
            # print(que)
            cnt += 1
            if cnt == K:
                print(que[-1])
                return

        que.append(10 * x + mod)
        # print(que)
        cnt += 1
        if cnt == K:
            print(que[-1])
            return

        if mod != 9:
            que.append(10 * x + mod + 1)
            # print(que)
            cnt += 1
            if cnt == K:
                print(que[-1])
                return

main()

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

def main():
    K = int(input())
    if K <= 0:
        print(K)

    que = deque(range(1,10))
    # print(que)
    cnt = 9
    while True:
        x = que.popleft()
        mod = x % 10

        if mod != 0:
            que.append(10 * x + mod - 1)
            # print(que)
            cnt += 1
            if cnt == K:
                print(que[-1])
                return

        que.append(10 * x + mod)
        # print(que)
        cnt += 1
        if cnt == K:
            print(que[-1])
            return

        if mod != 9:
            que.append(10 * x + mod + 1)
            # print(que)
            cnt += 1
            if cnt == K:
                print(que[-1])
                return

main()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

a = [9,8,7,6,5,4,3,2,1]
current_str = ''

for i in range(k):
  current_str = str(a.pop())
  candidates = []

  if current_str[-1] == "0":
    cp = current_str + "0"
    cp1 = current_str + "1"

    candidates.append(int(cp))
    candidates.append(int(cp1))
  elif current_str[-1] == "9":
    cp = current_str + "8"
    cp1 = current_str + "9"
    
    candidates.append(int(cp))
    candidates.append(int(cp1))
  else:
    cp = current_str + str(int(current_str[-1]) - 1)
    cp1 = current_str + current_str[-1]
    cp2 = current_str + str(int(current_str[-1]) + 1)

    candidates.append(int(cp))
    candidates.append(int(cp1))
    candidates.append(int(cp2))
    

  for c in candidates:
    a.insert(0, c)

print(current_str)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

a = [9,8,7,6,5,4,3,2,1]
current_str = ''

for i in range(k):
  current_str = str(a.pop())
  current = list(current_str)
  candidates = []

  if current[-1] == "0":
    cp = current.copy()
    cp1 = current.copy()
    
    cp.append("0")
    cp1.append("1")

    candidates.append(int(''.join(cp)))
    candidates.append(int(''.join(cp1)))
  elif current[-1] == "9":
    cp = current.copy()
    cp1 = current.copy()
    
    cp.append("8")
    cp1.append("9")

    candidates.append(int(''.join(cp)))
    candidates.append(int(''.join(cp1)))
  else:
    cp = current.copy()
    cp1 = current.copy()
    cp2 = current.copy()

    cp.append(str(int(current[-1]) - 1))
    cp1.append(str(int(current[-1])))
    cp2.append(str(int(current[-1]) + 1))

    candidates.append(''.join(cp))
    candidates.append(''.join(cp1))
    candidates.append(''.join(cp2))
    

  for c in candidates:
    a.insert(0, int(c))

print(current_str)

Submission status: Time Limit Exceeded

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


def solve(K: int):

    ct = 0
    q = [1,2,3,4,5,6,7,8,9]
    while(len(q)>0):
        a = q.pop(0)
        al = a % 10
        ct += 1 
        if ct == K:
            print(a)
            break

        if al != 0:
            q += [a*10+al - 1]
        q += [a*10+al]
        if al != 9:
            q += [a*10+al + 1]

        # print(q)


    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S='10'
Input=int(input())
A=[]
while Input!=len(A)+9:
    count=0
    for i in range(len(S)-1):
        if abs(int(S[i])-int(S[i+1])) <=1:
            count+=1
        if count==len(S)-1:
            A.append(S)
    S=str(int(S)+1)
print(int(A[-1]))

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
Q=[9,8,7,6,5,4,3,2,1]


for i in range(1,K+1):
    deq=Q.pop()
    mod=deq%10
    if mod!=0:
        Q.insert(0,10*deq+mod-1)
    Q.insert(0,10*deq+mod)
    if mod!=9:
        Q.insert(0,10*deq+mod+1)
print(deq)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
Queue = [i for i in range(9,1-1,-1)]
k = 100000
for i in range(k):
    x = Queue.pop(-1)
    if x%10 != 0:
        Queue.insert(0, x*10 + x%10 -1)
    Queue.insert(0, x*10 + x%10)
    if x%10 != 9:
        Queue.insert(0, x*10 + x%10 +1)
    if i == k-1:print(x)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

count = 0
j = 0

while count < K:
  j = int(j)
  j += 1
  if len(str(j)) == 1:
    count += 1
  else:
    j = str(j)
    k = 0
    for i in range(len(j)-1):
      if abs( int(j[i]) - int(j[i+1]) ) > 1:
        k = 1
    if k == 0:
      count += 1
      
print(j)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
cnt = 0

if n<10:
    print(n)
else:
    cnt = 9
    isLunLun = 1
    for i in range(10,3234566668):
        digit_list = list(map(int,list(str(i))))
        for j in range(0,len(digit_list)-1):
            if abs(digit_list[j] - digit_list[j+1]) >1:
                isLunLun = 0
                break
        if isLunLun == 1:
            cnt += 1
        isLunLun = 1
        if cnt == n:
            print(i)
            break

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def sovle(x):
    count=0
    for i in range(0, 9):
        if x[i] != 0:
            count += 1
        if count!=0:
            if abs(x[i]-x[i+1])>1:
                return False
    return True



if __name__ == '__main__':
    target=int(input())
    n=0
    a=[0,0,0,0,0,0,0,0,0,0]
    while n<target:
        a[9]+=1
        x=9
        while x>=1:
           if a[x]>=10:
               a[x-1]+=1
               a[x]-=10
           x-=1
        if a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]==0:
            n+=1
        elif sovle(a):
            n+=1
    result=""
    count=0
    for i in a:
        if i!=0:
            count+=1
        if count!=0:
            result+=str(i)
    print(result)

Submission status: Time Limit Exceeded

Solution code:
def sovle(x):
    s=str(x)
    for i in range(0, len(s)-1):
        if abs(int(s[i])-int(s[i+1]))>1:
            return False
    return True



if __name__ == '__main__':
    target=int(input())
    n=0
    num=0
    while(n<target):
        num+=1
        if(num<10):
            n+=1
        elif sovle(num):
            n+=1

    print(num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
k = int(input())

for i in range(k):
  f = x.pop(0)
  if(f % 10 != 0):	x.append(10 * f + f % 10 - 1)
  x.append(10 * f + f % 10)
  if(f % 10 != 9):	x.append(10 * f + f % 10 + 1)
print(f)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
b = 10
c = 9
while c <= k-1:
    B = str(b)
    for i in range(len(B)-1):
        if abs(int(B[i])-int(B[i+1])) > 1:
            b += 1
            break
    else:
        a.append(b)
        b += 1
        c += 1
print(a[k])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

count = 0

for i in range(1,3234566669):
  li = [int(n) for n in str(i)]
  
  for ii in range(1, len(li)+1):
    if ii == 1 and len(li) != 1:
      nn = abs(li[0]-li[1])
    elif ii == 1 and len(li) == 1:
      nn = li[0]
    elif ii == len(li):
      nn = abs(li[ii-1]-li[ii-2])
    else:
      nn1 = abs(li[ii-1]-li[ii])
      nn2 = abs(li[ii-2]-li[ii-1])
      nn = nn1+nn2 / 2
      
    if nn <= 1:
      count += 1
      
      if count == k:
        break
        
print(i)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
a=0
i=0
while i<K:
    u=0
    a+=1
    s=str(a)
    for j in range(len(s)-1):
        if abs(int(s[j])-int(s[j+1]))>1:
            u=1
            break
    if u==0:
        i+=1
print(a)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
a=0
i=0
while i<K:
    u=0
    a+=1
    s=str(a)
    for j in range(len(s)-1):
        if abs(int(s[j])-int(s[j+1]))>1:
            break
        u+=1
    if u==len(s)-1:
        i+=1
print(a)

Submission status: Time Limit Exceeded

Solution code:

def func(num):
    str_num=str(num)

    keta=len(str_num)

    if keta==1:
        return 1

    ans=1
    for j in range(2,keta+1):
        y=int(str_num[-j])-int(str_num[-j+1])
        if y==-1 or y==0 or y==1:
            ans=1
        else:
            return 0
    return ans

input = int(input())

count=0
for i in range(1,1000000000):
    x=func(i)
    if x==1:
        count+=1
    if input==count:
        print(i)
        break

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
li = []


def runruncheck(num):
    num_str = str(num)
    num_array = list(map(int, num_str))
    flag = True

    for j in range(len(num_str) - 1):
        if abs(num_array[j] - num_array[j + 1]) > 1:
            flag = False

    return flag


for i in range(1, 10 ** 7):
    if runruncheck(i):
        li.append(i)

print(li[k-1])