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:
K = int(input()) -1
q = list(range(1,10))
while K > 0:
    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)
    K -= 1
print(q[0])

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
n=0
c=0
while 1:
  n+=1
  j=True
  n_str=str(n)
  for i in range(len(n_str)-1):
    if abs(int(n_str[i]) - int(n_str[i+1])) > 1:
      j=False
  if j:
    c+=1
  if c==K:
    print(n)
    break

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
A=[x for x in range(K*10000)]
B=[]
j=0
for x in A:
    z=str(x)
    n=len(z)
    for i in range(n-1):
        y=int(z[i])-int(z[i+1])
        if abs(y)<=1:
            j+=1
    if j==(n-1):
        B.append(x)
        j=0
    else:
        j=0
    if len(B)==K+1:
        break
print(B[K])

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
A=[x for x in range(K*10000)]
B=[]
j=0
for x in A:
    z=str(x)
    n=len(z)
    for i in range(n-1):
        y=int(z[i])-int(z[i+1])
        if abs(y)<=1:
            j+=1
    if j==(n-1):
        B.append(x)
        j=0
    else:
        j=0
    if len(B)==K+1:
        break
print(B[K])

Submission status: Time Limit Exceeded

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

def lunlun(ans):
    a = True
    c = len(str(ans))
    for i in range(c-1):
        r1 = ans % 10
        ans = int(ans/10)
        r2 = ans % 10
        if abs(r1-r2) > 1:
            a = False
    return a

while k > 0:
    ans += 1
    if lunlun(ans):
        k -= 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
if K <= 12:
    print(K)
else:
    count = 13
    num = 21
    runrun = []
    while True:
        str_num = str(num)
        len_num = len(str_num)
        counts = 0
        for keta in range(1, len_num):
            if int(str_num[keta])+1 >= int(str_num[keta-1]):
                if int(str_num[keta])-1 <= int(str_num[keta-1]):
                    counts += 1
        if counts == len_num-1:
            if count == K:
                print(num)
                break
        num += 1
        count += 1

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
N=0 #現在のルンルン数の数
i=0
while N<K:
    i+=1
    s=str(i)
    #ルンルン数のチェック
    t=0
    for j in range(len(s)-1):
        if abs(int(s[j])-int(s[j+1]))<=1:
            t+=1
        else:
            break
    if t==len(s)-1: #すべてのケタが条件を満たしていれば
        N+=1

print(i)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def lunlun(x):
  X = collections.deque(str(x))
  if len(X)==1:
    return True
  for i in range(len(X)-1):
   if abs(int(X[1]) - int(X.popleft())) >1:
     return False
  return True

i = 0
j = 1
while i<K:
  if lunlun(j):
    i +=1
  j += 1

print(j-1)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

def lunlun(n):
    x = str(n)
    if len(x)==1:
        return True
    else:
        for i in range(len(x)-1):
            if abs(int(x[i])-int(x[i+1]))>1:
                return False
        else:
            return True

i = 0
j = 1
while i<K:
  if lunlun(j):
    i +=1
  j += 1

print(j-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
lunlun = list(range(1, 10))

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

print(lunlun.pop(0))

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
lunlun = list(range(1, 10))

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

print(lunlun.pop(0))

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

k = int(readline())
q = [(i + 1) for i in range(9)]
if k < 10:
    print(k)
cnt = 9
while q:
    x = q.pop(0)
    y = int(str(x)[-1])
    if y != 0:
        cnt += 1
        if cnt == k:
            print(10 * x + y - 1)
            exit()
        q.append(10 * x + y - 1)
    cnt += 1
    if cnt == k:
        print(10 * x + y)
        exit()
    q.append(10 * x + y)
    if y != 9:
        cnt += 1
        if cnt == k:
            print(10 * x + y + 1)
            exit()
        q.append(10 * x + y + 1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
if (k<=12):
	print(k)
	exit(0)
c = 12
n = "13"
while(c<k):
	l = True
	for i in range(len(n)-1):
		diff = abs(int(n[i])-int(n[i+1]))
		l &= diff <= 1
	if (l):
		c += 1
	n = str(int(n)+1)
print(int(n)-1)

Submission status: Time Limit Exceeded

Solution code:
p=int(input())
def kkk(x):
    if x>=1 and x<=9:
        return 0
    else:
        x=str(x)
        a=list(x)
        count=0
        for i in range(len(a)-1):
            if int(a[i])-int(a[i+1])>1 or int(a[i])-int(a[i+1])<-1:
                count+=1
                
        if count==0:
            return 0
        else:
            return 1
total=0
for y in range(1,10000000):
    if total==p:
        break
    if total<p:
        if kkk(y)==0:
            total+=1
        y+=1
print(y-1)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())

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

for x in range(a-1):
  tmp = N.pop(0)
  if tmp%10 != 0:
    N.append(tmp*10+tmp%10-1)
  N.append(tmp*10+tmp%10)
  if tmp%10 != 9:
    N.append(tmp*10+tmp%10+1)
print(N.pop(0))

Submission status: Time Limit Exceeded

Solution code:
def main():
    k = int(input())
    que = [1,2,3,4,5,6,7,8,9]
    cnt = 0
    while cnt!= k:
        x = que.pop(0)
        cnt += 1
        if x%10!=0:
            que.append(x*10+x%10-1)
        que.append(x*10+x%10)
        if x%10!=9:
            que.append(x*10+x%10+1)
    print(x)

            
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    k = int(input())
    que = [1,2,3,4,5,6,7,8,9]
    cnt = 0
    while cnt!= k:
        x = que.pop(0)
        cnt += 1
        if x%10==0:
            que.append(x*10)
            que.append(x*10+1)
        elif x%10==9:
            que.append(x*10+8)
            que.append(x*10+9)
        else:
            que.append(x*10+x%10-1)
            que.append(x*10+x%10)
            que.append(x*10+x%10+1)
    print(x)

            
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
A = int(input())

lunlun = 0
th = 0

while(True):
    if(th == A):
        break

    lunlun += 1
    lunstr = str(lunlun)

    if len(lunstr) == 1:
        th += 1
        continue

    lun_flag = True
    for i in range(1, len(lunstr) ):
        if abs(int(lunstr[i-1]) - int(lunstr[i])) > 1:
            lun_flag = False
            break

    if lun_flag==True:
        th += 1

print(lunlun)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

def isLunlun(n):
    p = n % 10
    n = n // 10
    while n != 0:
        d = n % 10
        n = n // 10
        if abs(d - p) > 1:
            return False
        p = d
    return True

c = 1
i = 1
n = 0
while c <= k:
    if isLunlun(i):
        n = i
        c += 1
    i += 1


print(n)

Submission status: Time Limit Exceeded

Solution code:
def is_lunlun(x0, x1):
    return abs(int(x0) - int(x1)) <= 1
def minimize(s, j):
    start = int(s[-j])
    for i in range(j - 1,0,-1):
        if start != 0:
            start -= 1
            s[-i] = str(start)
        else:
            s[-i] = str(0)
    return s

# k = int(input())
for k in range(99900, 100000):
    if (k <= 10):
        print(k)
    else:
        counter = 10
        i = 10
        while counter < k:
            s = list(str(i + 1))
            if not is_lunlun(s[-2], s[-1]):
                for j in range(2, len(s) + 1):
                    if s[-j] == '9':
                        s = minimize(s, j)
                    else:
                        s[-j] = str(int(s[-j]) + 1)
                    if j == len(s) or is_lunlun(s[-j], s[-(j + 1)]):
                        s = minimize(s, j)
                        break
                i = int("".join(s))
            else:
                i += 1
            counter += 1
        print(i)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
n = 0
i = 0
while True:
    i += 1
    i = str(i)[0] + str(i) + str(i)[-1]
    i_len = len(i) - 1
    flag = False
    for j in range(i_len):
        if abs(int(i[j+1]) - int(i[j])) <= 1:
            pass
        else:
            break

        if j == (i_len - 1):
            flag = True
            break

    if flag == True:
        n += 1
        flag = False

    if n == k:
        i = int(i[1:-1])
        break

    i = int(i[1:-1])
print(i)

Submission status: Time Limit Exceeded

Solution code:
k= int(input())
count= 0
num=1
if k<10:
    print(k)
else:
    while count != k:
        flag=0
        temp= str(num)
        numlist= list(temp)
        for i in range(0,len(numlist)-1):
            dis= int(numlist[i])-int(numlist[i+1])
            if abs(dis) >1:
                flag =1
                break
        if flag==0:
            count= count+1
        num= num+1
    print(num-1)

Submission status: Time Limit Exceeded

Solution code:
k= int(input())
count= 0
num=1
if k<10:
    print(k)
else:
    while count != k:
        flag=0
        temp= str(num)
        numlist= list(temp)
        for i in range(0,len(numlist)-1):
            dis= int(numlist[i])-int(numlist[i+1])
            if abs(dis) >1:
                flag =1
        if flag==0:
            count= count+1
        num= num+1
    print(num-1)

Submission status: Time Limit Exceeded

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

for k in range(9):
    n.append(k + 1)

i = 10

while len(n) < K:
    i_dig = len(str(i))
    result = True
    for j in range(i_dig - 1):
        i_dig_1 = int(str(i)[j])
        i_dig_2 = int(str(i)[j+1])
        if i_dig_1 - i_dig_2 < -1 or 1 < i_dig_1 - i_dig_2:
            result = False
    if result:
        n.append(i)
    i = i + 1

print(n[K-1])

Submission status: Time Limit Exceeded

Solution code:
import sys

target = int(input())

list_After = [str(n) for n in range(10)]
list_Before = []

count = 9

while 1:
  list_Before = list_After
  list_After = []
  for i in range(10):
    flag = 0
    for element in list_Before:
      if (abs(i - int(element[0])) >= 2) & (flag == 1):
        break
      elif abs(i - int(element[0])) >= 2:
        continue
      else:
        flag = 1
        list_After.append(str(i) + element)
        if i != 0:
          count += 1
          if count == target:
            print(str(i) + element)
            sys.exit()

Submission status: Time Limit Exceeded

Solution code:
import sys

target = int(input())

list_After = [str(n) for n in range(10)]
list_Before = []

count = 9

while 1:
  list_Before = list_After
  list_After = []
  for i in range(10):
    flag = 0
    for element in list_Before:
      if (abs(i - int(element[0])) >= 2) & (flag == 1):
        break
      elif abs(i - int(element[0])) >= 2:
        continue
      else:
        list_After.append(str(i) + element)
        if i != 0:
          count += 1
          if count == target:
            print(str(i) + element)
            sys.exit()

Submission status: Time Limit Exceeded

Solution code:
num=int(input())
count=0
num1=1
while count!=num:
  num2=str(num1)
  flag=0
  if len(num2)==1:
    ans=num1
    count=count+1
  else:
    for j in range(len(num2)-1):
      if abs(int(num2[j])-int(num2[j+1]))>=2:
        flag=1
        break
      else :
        continue
    if flag==0:
      ans=num1
      count=count+1
  num1=num1+1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
li=[[1,2,3,4,5,6,7,8,9]]
for i in range(9):
    tmp=[]
    for i2 in li[-1]:
        if i2%10!=0:
            tmp.append(i2*10+(i2%10-1))
            tmp.append(i2*10+(i2%10))
        if i2%19!=9:
            tmp.append(i2*10+(i2%10+1))
            li.append(tmp)
ans=[]
for i in range(len(li)):
    for i2 in range(len(li[i])):
        ans.append(li[i][i2])
ans=list(set(ans))
print(ans[k-1])

Submission status: Time Limit Exceeded

Solution code:
k=input()
count=0
judge=0
for i in range(1,10**int(k)):
  for j in range(len(str(i))-1):
    if abs(int(str(i)[j])-int(str(i)[j+1]))>1:
      judge+=1
  if judge==0:
    count+=1
  judge=0
  if count==int(k):
    print(i)
    break

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
Que = list(range(1,10))
for i in range(K):
    x = Que.pop(0)
    a = x%10
    if a !=0:
        Que.append(10*x +a -1)
    Que.append(10*x +a )
    if a != 9:
        Que.append(10*x +a +1)
print(x)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
abs = 0
cnt = 0

x = 1
while True:
  flag = True
  s = str(x)  
  for i in range(len(s)-1):
    if int(s[i]) > int(s[i + 1]):
      abs = int(s[i]) - int(s[i + 1])
    else:
      abs = int(s[i + 1]) - int(s[i])
    
    if abs > 1:
      flag = False
      break
  
  if flag == True:
    cnt += 1
  
  if cnt == K:
    print(x)
    exit()
  
  x += 1

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

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:
n = int(input())


queueList = []
oldList = []
for i in range(1,10):
	queueList.append(i)
# print(queueList)
if n < len(queueList):
	print(queueList[n-1])
	exit()
while(True):
	headElement = queueList[0]
	queueList.pop(0)
	oldList.append(headElement)
	for i in range(-1,2):
		newElement = headElement % 10 + i
		if newElement < 0 or 9 < newElement:
			continue
		if not (headElement*10 + newElement in oldList or headElement*10 + newElement in queueList):
			queueList.append(headElement*10 + newElement)
	if len(oldList) == n:
		break
print(oldList[-1])
# print(queueList[0])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())


queueList = []
oldList = []
for i in range(1,10):
	queueList.append(i)
# print(queueList)
if n < len(queueList):
	print(queueList[n-1])
	exit()
while(True):
	headElement = queueList[0]
	queueList.pop(0)
	oldList.append(headElement)
	for i in range(-1,2):
		newElement = headElement % 10 + i
		if newElement < 0 or 9 < newElement:
			continue
		if not (headElement*10 + newElement in oldList or headElement*10 + newElement in queueList):
			queueList.append(headElement*10 + newElement)
	if len(oldList) == n:
		break
print(oldList[-1])

Submission status: Time Limit Exceeded

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

K = int(input())


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

x = 0
i = 0
# K回繰り返す
while i < K:
    # x = dequeue
    x = queue.pop(0)

    one = x % 10
    # xの一桁目が0でなければ(x * 10 + xの一桁目に1加算した値)をenqueue
    if one != 0:
        queue.append(x * 10 + one - 1)

    # x * 10をenqueue
    queue.append(x * 10 + one)

    # xの一桁目が9でなければ(x * 10 - xの一桁目から1減算した値)をenqueue
    if one != 9:
        queue.append(x * 10 + one + 1)

    i += 1

# xが答え
print(x)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
 
lunlun = []
 
end = False
while True:
    val = 0
    while True:
        val += 1
        val_list = [int(x) for x in list(str(val))]
        is_lun = True 
        for x in range(len(val_list) - 1):
            if abs(val_list[x] - val_list[x + 1]) <= 1:
                continue
            else:
                is_lun = False
        if is_lun:
            lunlun.append(val)
        else:
            continue
        if len(lunlun) == k:
            end = True
            break
    if end:
        break
 
print(lunlun[k - 1])

Submission status: Time Limit Exceeded

Solution code:
k=int(input())

a=[]
i=1
d=0
while True:
    if len(str(i))==1:
        a.append(i)
    elif len(str(i))==2:
        I=str(i)
        c=abs(int(I[0])-int(I[1]))
        if c<=1:
            a.append(i)   
            
    elif len(str(i))==3:
        I=str(i)
        for j in range(2):
            c=abs(int(I[j])-int(I[j+1]))
            if c<=1:
                d=d+1
        if d==2:
            a.append(i)
        d=0
        
    elif len(str(i))==4:
        I=str(i)
        for j in range(3):
            c=abs(int(I[j])-int(I[j+1]))
            if c<=1:
                d=d+1
        if d==3:
            a.append(i) 
        d=0
        
    elif len(str(i))==5:
        I=str(i)
        for j in range(4):
            c=abs(int(I[j])-int(I[j+1]))
            if c<=1:
                d=d+1
        if d==4:
            a.append(i)   
        d=0
        
    elif len(str(i))==6:
        I=str(i)
        for j in range(5):
            c=abs(int(I[j])-int(I[j+1]))
            if c<=1:
                d=d+1
        if d==5:
            a.append(i)
        d=0
    
    elif len(str(i))==7:
        I=str(i)
        for j in range(6):
            c=abs(int(I[j])-int(I[j+1]))
            if c<=1:
                d=d+1
        if d==6:
            a.append(i)
            
        d=0    
        
    elif len(str(i))==8:
        I=str(i)
        for j in range(7):
            c=abs(int(I[j])-int(I[j+1]))
            if c<=1:
                d=d+1
        if d==7:
            a.append(i)
            
        d=0    
        
    i=i+1
    if i==10000000:
        break

print(a[k-1])

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
ls=[1,2,3,4,5,6,7,8,9,10,11,12]
i=21
while len(ls)<10**5:
    si=str(i)
    for s,n in zip(si, si[1:]):
        if not abs(int(s)-int(n))<=1:
            break
        if n==si[-1]:
            ls.append(i)
    i+=1
print(ls[k-1])

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

def barasu(A):
  ans = []
  while(True):
    a = A % 10
    if A/10 < 1:
      ans.append(int(a))
      return ans
      break 
    else:
      A = (A-a)/10
      ans.append(int(a))
    
    
def kakuninn(arr):
  if len(arr) == 1:
    return 1
  else:
    for i in range(len(arr)-1):
      sa = arr[i] - arr[i+1]
      if (sa < -1) or (sa > 1):
        return 0
        break
      if i == len(arr)-2:
        return 1

i=1
count = 0   
      
while(True):
  if kakuninn(barasu(i)) == 1:
    count += 1
    if count == K:
      print(i)
      break
  i += 1

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

if k < 10:
    print(k)
else:
    count = 9
    n = 9
    while count < k or up == True:
        up = False
        n += 1
        c = str(n)
        for i in range(len(c)-1):
            if abs(int(c[i]) - int(c[i+1])) > 1:
                up = True
                break
        if up == False:
            count += 1
    print(n)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
q = [1, 2, 3, 4, 5, 6, 7, 8, 9]
ans = 0
for i in range(k):
    ans = q.pop(0)
    x = ans
    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(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

def JudgeLunLun(num):
  val = num
  next = 0
  if num <= 12:
    val = num
  else:
    # 真面目なルンルン数判定。配列に1文字ずつ格納して全桁ループ処理して判定
    # 加算処理に備えて文字として扱う
    A = list(str(num))
    for i in range(len(A)-1):
      if abs(int(A[i])-int(A[i+1])) > 1:
        val = 0
        head = ''.join(A[:i+1])
        body = str(int(A[i+1]) +1)
        tail = '0' * (len(A) - (i+2))
        if body == '10':
          head = str(int(head)+1)
          body = '0'
        # 編集後の値を結合して数値変換して返す
        next = int(head+body+tail)
  
  return val, next

def main():
  K = int(input())
  cnt = 0
  i = 1
  while cnt < K:
    val, next = JudgeLunLun(i)
    # ルンルン数判定
    if val > 0:
      i += 1
      cnt += 1
      if cnt == K:
        break
    else:
      i = next
    
  print(val)

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:

def f():
  k = int(input())
  c = 0
  x = 0
  sx = 0
  while c < k:
    x+=1
    sx = str(x)
    c+=1
    for i in range(len(sx)-1):
      if abs(int(sx[i]) - int(sx[i+1])) > 1:
        c-=1
        break
  return x
import sys
sys.setrecursionlimit(100000)


print(f())

Submission status: Time Limit Exceeded

Solution code:

def f(k):
  c = 0
  x = 0
  sx = 0
  while c < k:
    x+=1
    sx = str(x)
    c+=1
    for i in range(len(sx)-1):
      if abs(int(sx[i]) - int(sx[i+1])) > 1:
        c-=1
        break
  return x
import sys
sys.setrecursionlimit(1000000)
k = int(input())

print(f(k))

Submission status: Time Limit Exceeded

Solution code:
from copy import deepcopy
k = int(input())

lun = []
for i in range(1,10):
    lun.append(i)

if k <= 9:
    print(lun[k-1])
    exit()

prev_lun = deepcopy(lun)
while True:
    for pl in prev_lun:
        for i in [-1, 0, 1]:
            d = pl%10 + i
            if not 0 <= d <= 9:
                continue
            lun.append(pl*10 + d)
            if len(lun) == k:
                print(lun[k-1])
                exit()
                
    prev_lun = []

Submission status: Time Limit Exceeded

Solution code:
class Queue:
    def enque(self, x, l):
        l.append(x)
        return l

    def deque(self, l):
        num = l[0]
        l.pop(0)
        return num

k = int(input())

queue = Queue()
l = [1,2,3,4,5,6,7,8,9]

for i in range(k):
    x = queue.deque(l)
    if x % 10 != 0:
        l = queue.enque(10*x + (x%10) -1, l)
    l = queue.enque(10*x + (x%10), l)
    if x % 10 != 9:
        l = queue.enque(10*x + (x%10) +1, l)
print(x)

Submission status: Time Limit Exceeded

Solution code:
class Queue:
    def enque(self, x, l):
        l.append(x)
        return l

    def deque(self, l):
        num = l[0]
        l.pop(0)
        return num

k = int(input())

queue = Queue()
l = list()
for x in range(1,10):
    queue.enque(x,l)

for i in range(k-1):
    x = queue.deque(l)
    if x % 10 != 0:
        l = queue.enque(10*x + (x%10) -1, l)
    l = queue.enque(10*x + (x%10), l)
    if x % 10 != 9:
        l = queue.enque(10*x + (x%10) +1, l)
print(queue.deque(l))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

c = 0
a = 1
i = 1
while c < n:
    s = str(i)
    f = 0
    j=0
    while j < len(s) -1:
        if abs(int(s[j]) - int(s[j+1])) > 1:
            f = 1
            break
        j = j + 1
    if f == 0:
        # print(i)
        c = c + 1
        a = i
    if c == n:
        break
    i += 1

print(a)

Submission status: Time Limit Exceeded

Solution code:
import sys

def JudgeLunLun(num):
  val = num
  if num <= 12:
    val = num
  else:
    # 真面目なルンルン数判定。配列に1文字ずつ格納して全桁ループ処理して判定
    A = [int(x) for x in list(str(num))]
    for i in range(len(A)-1):
      if abs(A[i]-A[i+1]) > 1:
        val = 0
        break
  return val

def main():
  K = int(input())
  cnt = 0
  for i in range(1, sys.maxsize):
    num = JudgeLunLun(i)
    # ルンルン数判定
    if num > 0:
      cnt += 1
    if cnt == K:
      break
  print(num)

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:

k = int(input())


def lunlunfinder(k):
    l = [int(x) for x in list(str(k))]
    status = 0
    for i in range(len(l) - 1):
        if abs(l[i] - l[i + 1])  <= 1:
            continue
        else:
            status = 1
            break

    if status == 1:
        return False
    else:
        return True


lunlunlist = []
i = 1

while len(lunlunlist) < k:
    if lunlunfinder(i) == True:
        lunlunlist.append(i)
    i += 1

print(lunlunlist[k - 1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
Q = list(range(1,10))
k = 1
while True:
    x = Q.pop(0)
    if k == K:
        print(x)
        break
    if x%10 != 0:
        Q += [10*x + x%10 - 1]
    Q += [10*x + x%10]
    if x%10 != 9:
        Q += [10*x + x%10 + 1]
    k += 1

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

for i in range(n):
  x = list[0]
  mod_x = x%10
 # print(i,"番目　",x)
  list.pop(0)
  if mod_x != 0: list.append(10*x + (x%10) -1)
  list.append(10*x + (x%10))
  if mod_x != 9: list.append(10*x + (x%10) + 1)
print(x)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

for i in range(n):
  x = list[0]
  mod_x = x%10
 # print(i,"番目　",x)
  list.pop(0)
  if mod_x != 0:
    list.append(10*x + (x%10) -1)
    
  list.append(10*x + (x%10))
  
  if mod_x != 9:
    list.append(10*x + (x%10) + 1)

print(x)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

for i in range(n):
  x = list[0]
  mod_x = x%10
 # print(i,"番目　",x)
  list.pop(0)
  if mod_x != 0:
    list.append(10*x + (x%10) -1)
  list.append(10*x + (x%10))
  if mod_x != 9:
    list.append(10*x + (x%10) + 1)
print(x)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

if K < 10:
    print(K)
else:
    count = 0
    num = 1
    runrun = list(range(1, 10))
    while count != K:
        s = str(num)
        judge = 0
        for i in range(1, len(s)):
            if abs(int(s[i - 1]) - int(s[i])) <= 1:
                judge += 1
            else:
                break
        
        if judge == len(s) - 1:
            runrun.append(num)
            count += 1
            

        num += 1
    print(num - 1)

Submission status: Time Limit Exceeded

Solution code:
def isLunlun(n):
  digs = list(map(int, str(n)))
  N = len(digs)
  if N == 1:
    return True
  i = 0
  while i < (N - 1):
    if abs(digs[i]-digs[i+1]) > 1:
      return False
  return True
n = int(input())
st = 0
while n:
  st += 1
  if isLunlun(st):
    n -= 1
print(st)

Submission status: Time Limit Exceeded

Solution code:
def D():
    
    k=int(input())
    runrun=[i for i in range(1,10)]
    count=10
    runrun_count=9
            
    
    while runrun_count<k:
        
        len_count=0
        strcount=str(count)
        
        for i in range(1,len(strcount)):
            if abs(int(strcount[i])-int(strcount[i-1])) < 2 :
                len_count+=1
                continue
            else :
                break
        
        
        if len_count==len(strcount)-1:
            runrun.append(count)
            runrun_count+=1
            
        count+=1    
        
        
    print(runrun[k-1])
    
if __name__=='__main__':
    D()

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
if K < 13:
	print(K)
else:
	k = 12
	j = 12
	while k < K:
		j += 1
		J = [int(i) for i in str(j)]
		J = [abs(J[i]-J[i-1]) <= 1 for i in range(1,len(J))]
		if all(J):
			k += 1
	print(j)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
count=0
list2=[]
i=1
while(count!=n):
  s=str(i)
  for j in range(0,len(s)-1):
    if(abs(s[j]-s[j+1])<=1):
      count+=1
      list2.append(int(s))
print(list2[len(list2)-1])

Submission status: Time Limit Exceeded

Solution code:

K = int(input())
n = 0
cnt = 0
tmp = 0
while cnt < K:
    n = n + 1

    nDigit = []
    nDiv   = []
    flg = True
    digits = len(str(n))
    tmpN = n
    for i in range(0,digits) :
        nDigit.append(tmpN // (10 ** (digits-i-1)))
        tmpN = tmpN % (10 ** (digits-i-1))
    if len(nDigit) == 1 :
        cnt = cnt + 1
        tmp = n
    else :
        tR = 0
        for i in range(0,len(nDigit)-1) :
            if abs(nDigit[i] - nDigit[i+1]) > 1 :
                flg = False
                tR = i
                i = len(nDigit)
        if flg == True :
            cnt = cnt + 1
            tmp = n
        elif nDigit[tR] - nDigit[tR+1] < 0 :
            n = n - (n % (10 ** (digits - tR))) + (nDigit[tR] + 1) * (10 ** (digits-tR-1)) - 1
        elif nDigit[tR] - nDigit[tR+1] > 0 :
            n = n - (n % (10 ** (digits - tR-1))) + (nDigit[tR] - 1) * (10 ** (digits-tR-2)) - 1

#for i in range(0,len(LunList)) :
#    print(i,LunList[i])
print(n)

Submission status: Time Limit Exceeded

Solution code:

K = int(input())
n = 0
cnt = 0
tmp = 0
while cnt < K:

    n = n + 1
    nDigit = []
    nDiv   = []
    flg = True
    digits = len(str(n))
    tmpN = n
    for i in range(0,digits) :
        nDigit.append(tmpN // (10 ** (digits-i-1)))
        tmpN = tmpN % (10 ** (digits-i-1))
    if len(nDigit) == 1 :
        cnt = cnt + 1
        tmp = n
    else :
        tR = 0
        for i in range(0,len(nDigit)-1) :
            if abs(nDigit[i] - nDigit[i+1]) > 1 :
                flg = False
                tR = i
                i = len(nDigit)
        if flg == True :
            cnt = cnt + 1
            tmp = n
        elif nDigit[tR] - nDigit[tR+1] < 0 :
            n = n - (n % (10 ** (digits - tR))) + (nDigit[tR] + 1) * (10 ** (digits-tR-1)) - 1

#for i in range(0,len(LunList)) :
#    print(i,LunList[i])
print(n)

Submission status: Time Limit Exceeded

Solution code:

K = int(input())
n = 0
LunList = [0]
cnt = 0
tmp = 0
while cnt < K:
    n = n + 1
    LunList.append(0)
    nDigit = []
    nDiv   = []
    flg = True
    digits = len(str(n))
    tmpN = n
    for i in range(0,digits) :
        nDigit.append(tmpN // (10 ** (digits-i-1)))
        nDiv.append(tmpN)
        tmpN = tmpN % (10 ** (digits-i-1))
    if len(nDigit) == 1 :
        cnt = cnt + 1
        LunList[n] = LunList[tmp] + 1
        tmp = n
    else :
        for i in range(0,len(nDigit)-1) :
            if abs(nDigit[i] - nDigit[i+1]) > 1 :
                flg = False
        if flg == True :
            cnt = cnt + 1
            LunList[n] = LunList[tmp] + 1
            tmp = n
print(n)