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

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

cnt = 1

while(cnt <= k) : 
    x = Queue.pop(0)
    xx = x
    if len(str(xx)) >= 2 : 
        while(len(str(xx)) >= 2) : 
            xx = xx % 10

    ## 1つ目            
    if xx != 0 : 
        y = int("".join(map(str, [x, xx-1])))
        Queue.append(y)
        
    ## 2つ目            
    y = int("".join(map(str, [x, xx])))    
    Queue.append(y)

    ## 3つ目            
    if xx != 9 : 
        y = int("".join(map(str, [x, xx+1])))
        Queue.append(y)

    cnt += 1
            
print(x)

Submission status: Time Limit Exceeded

Solution code:
"""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, 101, 110, 111, 112, 121, 122, 123, 210, 211, 212, 221, 222, 223, 232, 233, 234, 321, 322, 323, 33

1 -> 10,11,12 -> 100,101 ,110,111,112, 121,122,123

2 -> 21,22,23 -> 210,211,212, 221,222,223, 232,233,234"""
def main():
    n = int(input())
    queue = [i for i in range(1,10)]
    while True:
        if n <= 1:
            print(queue[0])
            return
        tmp = queue.pop(0)
        n -= 1
        if tmp%10 != 0:
            queue.append(tmp*10 + tmp%10 - 1)
        queue.append(tmp*10 + tmp%10)
        if tmp%10 != 9:
            queue.append(tmp*10 + tmp%10 + 1)
            
main()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

qu = list(range(1,10))

cnt = 0
while( cnt < k ):
  out = qu.pop(0)
  r = out%10
  if( r != 0 ):
    qu.append(10*out+r-1)
  qu.append(10*out+r)
  
  if( r!=9):
    qu.append(10*out+r+1)
  cnt+=1
    
print(out)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    
    queue = [i for i in range(1,10)]
    while True:
        if n == 1:
            print(queue.pop(0))
            break
        tmp = queue.pop(0)
        n -= 1
        if tmp%10 != 0:
            queue.append(tmp*10 + tmp%10 - 1)
        queue.append(tmp*10 + tmp%10)
        if tmp%10 != 9:
            queue.append(tmp*10 + tmp%10 + 1)
            
main()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

cnt = 1

while(cnt <= k) : 
    x = Queue.pop(0)
    xx = x
    if len(str(xx)) >= 2 : 
        while(len(str(xx)) >= 2) : 
            xx = xx % 10
    for i in range(0, 10, 1) : 
        if abs(xx - i) <= 1 : 
            y = int("".join(map(str, [x, i])))
            Queue.append(y)
    cnt += 1
            
print(x)

Submission status: Time Limit Exceeded

Solution code:
"""
1 -> 10,11,12 -> 100,101 ,110,111,112, 121,122,123

2 -> 21,22,23 -> 210,211,212, 221,222,223, 232,233,234"""

n = int(input())

queue = [i for i in range(1,10)]
while n != 1:
    tmp = queue.pop(0)
    n -= 1
    if tmp%10 != 0:
        queue.append(tmp*10 + tmp%10 - 1)
    queue.append(tmp*10 + tmp%10)
    if tmp%10 != 9:
        queue.append(tmp*10 + tmp%10 + 1)
print(queue.pop(0))

Submission status: Time Limit Exceeded

Solution code:
def dfs(inParam, digits, lunlunCount, lunlun):
    if len(inParam) != digits:
        if int(inParam[len(inParam)-1]) == 0:
            nextNumList = [0, 1]
        elif int(inParam[len(inParam)-1]) == 9:
            nextNumList = [8, 9]
        else:
            nextNum = int(inParam[len(inParam)-1])
            nextNumList = [nextNum-1, nextNum, nextNum+1]
        
        for item in nextNumList:
            myTupp = dfs(inParam+str(item), digits, lunlunCount, lunlun)
            lunlunCount = myTupp[0]
            if myTupp[2] == 'e':
                return myTupp
        
        return myTupp
    
    else:
        lunlunCount += 1
        state = 'c'

        if lunlunCount == lunlun:
            state = 'e'
            print(inParam)

        return (lunlunCount, inParam, state)

K = int(input())

mylunlun = 0
mydigits = 1
while mylunlun != K:
    for indx in range(1, 10):
        mylunlun, lunlunNumber, _ = dfs(str(indx), mydigits, mylunlun, K)
        # if mylunlun == K:
        #     break
    
    if mylunlun == K:
        break

    mydigits += 1

Submission status: Time Limit Exceeded

Solution code:
"""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, 101, 110, 111, 112, 121, 122, 123, 210, 211, 212, 221, 222, 223, 232, 233, 234, 321, 322, 323, 33

1 -> 10,11,12 -> 100,101 ,110,111,112, 121,122,123

2 -> 21,22,23 -> 210,211,212, 221,222,223, 232,233,234"""

n = int(input())

queue = [i for i in range(1,10)]
while True:
    if n == 1:
        print(queue.pop(0))
        break
    tmp = queue.pop(0)
    n -= 1
    if tmp%10 != 0:
        queue.append(tmp*10 + tmp%10 - 1)
    queue.append(tmp*10 + tmp%10)
    if tmp%10 != 9:
        queue.append(tmp*10 + tmp%10 + 1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

k = int(input())

q = [i for i in range(1, 10)]
if k <= 9:
    print(q[k-1])
    sys.exit()

cnt = 0
while True:
    if cnt == k:
        print(x)
        break
    x = q.pop(0)
    m = x % 10
    if m == 0:
        q.extend([10*x + m, 10*x + (m+1)])
    elif m == 9:
        q.extend([10*x + (m-1), 10*x + m])
    else:
        q.extend([10*x + (m-1), 10*x + m, 10*x + (m+1)])
    cnt += 1

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
runrun = [1,2,3,4,5,6,7,8,9]

i = 1

while len(runrun)<100000:
  s = len(str(i))
  cnt = 1
  for t in range(s-1):
    if -2<int(str(i)[t])-int(str(i)[t+1])<2:
      cnt += 1
  if cnt==s:
    runrun.append(i)
  i += 1
print(runrun[int(input())-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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 111 < K <= 328:
    n = 1000
    m = 111
elif 328 < K <= :
    n = 10000
    m = 328
"""

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
    elif 100000<=n<1000000:
        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]))
        n6 = int(str(ns[-6]))
        if -1 <= n1-n2 <= 1 and -1 <= n2-n3 <= 1 and -1 <= n3-n4 <= 1 and -1 <= n4-n5 <= 1 and -1 <= n5-n6 <= 1:
            m += 1
    elif 1000000<=n<10000000:
        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]))
        n6 = int(str(ns[-6]))
        n7 = int(str(ns[-7]))
        if -1 <= n1-n2 <= 1 and -1 <= n2-n3 <= 1 and -1 <= n3-n4 <= 1 and \
            -1 <= n4-n5 <= 1 and -1 <= n5-n6 <= 1 and -1 <= n6-n7 <= 1:
            m += 1
    elif 10000000<=n<100000000:
        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]))
        n6 = int(str(ns[-6]))
        n7 = int(str(ns[-7]))
        n8 = int(str(ns[-8]))
        if -1 <= n1-n2 <= 1 and -1 <= n2-n3 <= 1 and -1 <= n3-n4 <= 1 and \
            -1 <= n4-n5 <= 1 and -1 <= n5-n6 <= 1 and -1 <= n6-n7 <= 1 and -1 <= n7-n8 <= 1:
            m += 1
    elif 100000000<=n<1000000000:
        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]))
        n6 = int(str(ns[-6]))
        n7 = int(str(ns[-7]))
        n8 = int(str(ns[-8]))
        n9 = int(str(ns[-9]))
        if -1 <= n1-n2 <= 1 and -1 <= n2-n3 <= 1 and -1 <= n3-n4 <= 1 and \
            -1 <= n4-n5 <= 1 and -1 <= n5-n6 <= 1 and -1 <= n6-n7 <= 1 and -1 <= n7-n8 <= 1 and -1 <= n8-n9 <= 1:
            m += 1
    elif 1000000000<=n<10000000000:
        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]))
        n6 = int(str(ns[-6]))
        n7 = int(str(ns[-7]))
        n8 = int(str(ns[-8]))
        n9 = int(str(ns[-9]))
        n10 = int(str(ns[-10]))
        if -1 <= n1-n2 <= 1 and -1 <= n2-n3 <= 1 and -1 <= n3-n4 <= 1 and \
            -1 <= n4-n5 <= 1 and -1 <= n5-n6 <= 1 and -1 <= n6-n7 <= 1 and \
            -1 <= n7-n8 <= 1 and -1 <= n8-n9 <= 1 and -1 <= n9-n10 <= 1:
            m += 1






    if m == K:
        break

print(n)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

for i in range(K - 1):
    N = queue.pop(0)
    if N % 10 == 0:
        queue.append(N * 10)
        queue.append(N * 10 + 1)
    elif N % 10 == 9:
        queue.append(N * 10 + 8)
        queue.append(N * 10 + 9)
    else:
        queue.append(N * 10 + (N % 10 - 1))
        queue.append(N * 10 + N % 10)
        queue.append(N * 10 + (N % 10 + 1))
print(queue.pop(0))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
import math
# stdin = open("sample.txt")

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

K = int(stdin.readline().rstrip())
a = list(range(1,10))
b = []
attack = 100000
while attack > 0:
    go = a.pop(0)
    ue = go*10
    shimo = go%10
    b.append(go)
    if shimo == 0:
        a.append(ue)
        a.append(ue+1)
    elif shimo == 9:
        a.append(ue+shimo-1)
        a.append(ue+shimo)
    else:
        a.append(ue+shimo-1)
        a.append(ue+shimo)
        a.append(ue+shimo+1)
    attack -= 1

print(b[K-1])

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
queue=[i for i in range(1,10)]
for _ in range(k-1):
    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(queue[0])

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

K = int(input())

list = [1,2,3,4,5,6,7,8,9]
i = 0
for i in range(K):
    v = list.pop(0)

    t = v%10

    if t != 0:
        list.append(10*v + (t-1))

    list.append(10*v + t)

    if t != 9:
        list.append(10*v + (t+1))


print(v)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
import math
# stdin = open("sample.txt")

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

K = int(stdin.readline().rstrip())
a = list(range(1,10))
b = []
attack = 100000
while attack > 0:
    go = a.pop(0)
    ue = go*10
    shimo = go%10
    b.append(go)
    if shimo == 0:
        a += (ue,ue+1)
    elif shimo == 9:
        a += (ue+shimo-1,ue+shimo)
    else:
        a += (ue+shimo-1,ue+shimo,ue+shimo+1)
    attack -= 1

print(b[K-1])

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
def is_lunlun(n):
  a=n%10
  n//=10
  while n>0:
    b=n%10
    if abs(a-b)>1: return False
    a=b
    n//=10
  return True

c=0
i=1
while True:
  if is_lunlun(i): c+=1
  if c==K: break
  i+=1
print(i)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
import math
# stdin = open("sample.txt")

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

K = int(stdin.readline().rstrip())
a = list(range(1,10))
b = []

for i in range(100000):
    go = a.pop(0)
    ue = go*10
    shimo = go%10
    b.append(go)
    if shimo == 0:
        a += (ue,ue+1)
    elif shimo == 9:
        a += (ue+shimo-1,ue+shimo)
    else:
        a += (ue+shimo-1,ue+shimo,ue+shimo+1)

print(b[K-1])

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

for i in range(K):
    sample = nlist.pop(0)
        
    if sample%10 != 0:
        nlist.append(sample*10 - 1 + sample%10)
            
    nlist.append(sample*10 + sample%10)
        
    if sample%10 != 9:
        nlist.append(sample*10 + 1 + sample%10)      
    
print(sample)

Submission status: Time Limit Exceeded

Solution code:
# 時間がかかりすぎる

import numpy as np

K = int(input())

def runrun(n):
    if n < 10:
        return True
    
    ns = str(n)

    for i in range(len(ns)-1):
        if abs(int(ns[i]) - int(ns[i+1])) > 1:
            return False

    return True

R = 0
while K > 0:
    R += 1
    if runrun(R):
        K -= 1

print(R)

Submission status: Time Limit Exceeded

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

    if t != 0:
        list.append(10*v + (t-1))

    list.append(10*v + t)

    if t != 9:
        list.append(10*v + (t+1))


print(v)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

K = int(input())
N = np.arange(10**5)

def func(n):
	n_list = list(map(int,str(n)))
	b = n_list[1:]
	b.append(0)
	a_np = np.array(n_list)
	b_np = np.array(b)
	c_np = abs(a_np - b_np)
	c_np[-1] = 0
	return np.all(c_np<=1)

ans = []
for i in range(1,10**5+1):
	if func(i):
		ans.append(i)

print(ans[K-1])

Submission status: Time Limit Exceeded

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]
    mod = x%10
    if mod != 0:
        que.append(10*x+mod-1)
    que.append(10*x+mod)
    if mod != 9:
        que.append(10*x+mod+1)
print(x)

Submission status: Time Limit Exceeded

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'))
      i+=1
    elif int(k[-1])==9 :
      list1.append(int(str(k)+'8'))
      list1.append(int(str(k)+'9'))
      i+=1
    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: Time Limit Exceeded

Solution code:
K = int(input())
 
def is_runrun(N,bool_runrun):  
    s = str(N)
    s_array = list(map(int, s))  
    
    if(len(s_array)==1):
        return bool_runrun
    
    for i in range(len(s_array)-1):
        diff = s_array[i] - s_array[i+1]
        if not (diff==-1 or diff ==1 or diff ==0):
            bool_runrun = False
            return bool_runrun
    return bool_runrun
 
count = 0
i = 0
while(count<=K-1):
    i += 1
    
    if(is_runrun(i,bool_runrun = True)):
        count += 1
 
print(i)

Submission status: Time Limit Exceeded

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

Solution code:
K = int(input())
 
list = [1,2,3,4,5,6,7,8,9]
i = 0
while i!=K:
    v = list.pop(0)
    i += 1
    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*10+t-1)
        list.append(v*10+t)
        list.append(v*10+t+1)
 
print(v)

Submission status: Time Limit Exceeded

Solution code:
import queue

class Queue:
    def __init__(self,data = []):
        self.data = data
    def enqueue(self,x):
        self.data.append(x)
        return self.data
    def dequeue(self):
        if len(self.data) <= 0:
            print('Queue is Empty')
            return -1
        else:
            out = self.data[0]
            del self.data[0]
            return out
    def show(self):
        print(self.data)

    def list(self):
        return self.data


k = int(input())

# FIFOキューの作成
#q = queue.Queue()
q = Queue()

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

#q.show()

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

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

    q.enqueue(10 * x + x % 10)

    if not x % 10 == 9:
        q.enqueue(10 * x + x % 10 + 1)
    
print(x)
    #print(i+1,x,q.list())
    #q.show()

Submission status: Time Limit Exceeded

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*10+t-1)
        list.append(v*10+t)
        list.append(v*10+t+1)
 
print(v)

Submission status: Time Limit Exceeded

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

Solution code:
import sys
from collections import deque
sys.setrecursionlimit(10**7)
k = int(input())
ans = []
def bfs(que):
    finished = set()
    while que and len(ans) <= 10**6:
        x = que.popleft()
        ans.append(int(x))
        if x not in finished:
            finished.add(x)
            p = int(x[-1])
            que.append(x + str(p))
            if 1 <= p <= 8:
                que.append(x + str(p+1))
                que.append(x + str(p-1))
            elif p == 0:
                que.append(x + str(p+1))
            else:
                que.append(x + str(p-1))
que = deque([])
for i in range(1,10):
    que.append(str(i))
bfs(que)
ans.sort()
print(ans[k-1])

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

queue = list(range(1, 10))

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

print(x)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

for i in range(K):
    que.pop(0)
    temp = que[0]
    if i == K:
        break
    mod = temp % 10
    if mod == 0:
        que += [temp*10+(mod), temp*10+(mod)+1]
    elif temp % 10 == 9:
        que += [temp*10+(mod)-1, temp*10+(mod)]
    else:
        que += [temp*10+(mod)-1, temp*10+(mod), temp*10+(mod)+1]

print(que[0])

Submission status: Time Limit Exceeded

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,12):
	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[int(input())])

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

for i in range(K):
    que.pop(0)
    temp = que[0]
    if temp % 10 == 0:
        que.append(temp*10+(temp % 10))
        que.append(temp*10+(temp % 10)+1)
    elif temp % 10 == 9:
        que.append(temp*10+(temp % 10)-1)
        que.append(temp*10+(temp % 10))
    else:
        que.append(temp*10+(temp % 10)-1)
        que.append(temp*10+(temp % 10))
        que.append(temp*10+(temp % 10)+1)


print(que[0])

Submission status: Time Limit Exceeded

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

    if v%10 == 0:
        list.append(v*10)
        list.append(v*10+1)
    elif v%10 == 9:
        list.append(v*10+8)
        list.append(v*10+9)
    else:
        t = v%10
        list.append(v*10 + (t-1))
        list.append(v*10 + t)
        list.append(v*10 + (t+1))

print(v)

Submission status: Time Limit Exceeded

Solution code:

def diff_rule(a,b):
    if(abs(a-b)<=1):
        return True
    else:
        return False


def n_dig(n,i):
    brd = pow(10,n)
    if(i<brd):
        return True
    else:
        return False

def apper(it):
    d = 1
    a = 0
    b = 0
    while True:
        if(n_dig(d,it)):
            return True
        else:
            a = str(it)[-d]
            b = str(it)[-(d+1)]
            if(not(diff_rule(int(a),int(b)))):
                return False
            d = d + 1

def main():
    k = int(input())

    it = 0
    lun = 0

    while lun<k:
        it = it + 1

        if(apper(it)):
            lun = lun + 1

    print(it)
main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

K = int(input())

def Is_runrun(n):
    n = str(n)
    return all([abs(int(i1)-int(i2)) <= 1 for i1, i2 in zip(n[:-1], n[1:])])
        
if K <= 12:
    print(K)
else:
    K -= 12
    n = 13
    runruns = []
    while len(runruns) != K:
        if Is_runrun(n):
            runruns.append(n)
        n += 1
            
    print(runruns[-1])

Submission status: Time Limit Exceeded

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

for i in range(1, 10**9):
    if len(ansli)==K:
        print(ansli[K-1])
        exit()

    if 1<= i <=9:
        ansli.append(i)
        continue

    stri = str(i)
    leni = len(stri)

    for ii in range(leni-1):
        if int(stri[ii]) == int(stri[ii+1])-1 or \
            int(stri[ii]) == int(stri[ii+1]) or \
            int(stri[ii]) == int(stri[ii+1])+1:
            pass

        else:
            break

        if ii==leni-2:
            ansli.append(i)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
cnt = 10
i = 10
lunlun_nums = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
if cnt > K:
    output = K
else :
    while cnt < K:
        i += 1
        if i//10 in lunlun_nums:
            num = list(map(int,[l for l in str(i)]))
            if abs(num[-2] - num[-1]) <= 1:
                lunlun_nums.add(i)
                cnt += 1
    output = i
print(output)

Submission status: Time Limit Exceeded

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

def flag(cnt,listmp):
    for i in range(len(listmp)-1):
        if abs(listmp[i]-listmp[i+1]) > 1:
            return cnt
        # print('diff',listmp[i]-listmp[i+1])
    return cnt+1


def f(K):
    cnt =0
    num= 1
    while(1):
        listmp  =  [int(x) for x in list(str(num))]
        if num<10:
            cnt +=1
            num+=1
        else:
            cnt = flag(cnt,listmp)
            if K == cnt:
                return num
            num +=1


print(f(K))

Submission status: Time Limit Exceeded

Solution code:
url = "https://atcoder.jp/contests/abc161/tasks/abc161_d"

def main():
    n = int(input())

    end_r = 3234566667
    count = 0
    start = 0
    flg = False

    if n <= 12:
        print(n)
        exit()
    elif n <= 50000:
        count = n
    elif n > 50000:
        count = 100000 - n
        start = end_r
        flg = True
    while count != 0:
        if flg:
            start -= 1
        else:
            start += 1
        for i in range(len(str(start)) + 1):
            start_li = [int(v) for v in str(start)]
            if i == len(start_li) - 1:
                count -= 1
                break
            elif abs(start_li[i] - start_li[-1]) >= len(start_li):
                break
            elif abs(start_li[i + 1] - start_li[i]) >= 2:
                break


    print(start)







if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
K = int(input())
D = [str(i) for i in range(1, 10)]
cnt = 0
while cnt < K:
    v = D.pop(0)
    if v[-1] == "0":
        D.append(v + "0")
        D.append(v + "1")
    elif v[-1] == "9":
        D.append(v+"8")
        D.append(v+"9")
    else:
        D.append(v + str(int(v[-1]) - 1))
        D.append(v + v[-1])
        D.append(v + str(int(v[-1]) + 1))
    cnt += 1
print(v)

Submission status: Time Limit Exceeded

Solution code:

K = input("")
K = int(K)
m = 0
n = 0
while(m != K):
    n = int(n)
    n += 1
    if n < 10:
        m += 1
    elif 10<=n<100:
        n = str(n)
        n1 = str(n[-1])
        n2 = str(n[-2])
        n1 = int(n1)
        n2 = int(n2)
        if -1 <= n1-n2 <= 1:
            m += 1
    elif 100<=n<1000:
        n = str(n)
        n1 = str(n[-1])
        n2 = str(n[-2])
        n3 = str(n[-3])
        n1 = int(n1)
        n2 = int(n2)
        n3 = int(n3)
        if -1 <= n1-n2 <= 1 and -1 <= n2-n3 <= 1 :
            m += 1
    elif 1000<=n<10000:
        n = str(n)
        n1 = str(n[-1])
        n2 = str(n[-2])
        n3 = str(n[-3])
        n4 = str(n[-4])
        n1 = int(n1)
        n2 = int(n2)
        n3 = int(n3)
        n4 = int(n4)
        if -1 <= n1-n2 <= 1 and -1 <= n2-n3 <= 1 and -1 <= n3-n4 <= 1 :
            m += 1
    elif 10000<=n<=100000:
        n = str(n)
        n1 = str(n[-1])
        n2 = str(n[-2])
        n3 = str(n[-3])
        n4 = str(n[-4])
        n5 = str(n[-5])
        n1 = int(n1)
        n2 = int(n2)
        n3 = int(n3)
        n4 = int(n4)
        n5 = int(n5)
        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: Time Limit Exceeded

Solution code:
k = int(input())
def judg(x):
    list_x = list(str(x))
    flag = 0
    for i in range(len(list_x) - 1):
        if abs(int(list_x[i]) - int(list_x[i + 1])) <= 1:
            flag = 0
        else:
            flag = 1
            break
    if flag == 0:
        return True
    else:
        return False
ans = 1
if k == 1:
    print("1")
else:
    i = 1 #回数
    list_a = []
    ans = 1
    while(i != k or judg(ans) == False):
        if i == k:
            ans += 1
        if judg(ans) == True:
            i += 1
            ans += 1
            list_a.append(ans)
        else:
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# def lunlunChecker(N):
#   num = list(map(int,[l for l in str(N)]))
#    flag = True
#   for n in range(len(num)-1):
#       if abs(num[n]-num[n+1]) > 1:
#           flag = False
#           break
#   return flag
    
K = int(input())
cnt = 10
i = 10
lunlun_nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
if cnt > K:
    output = lunlun_nums.index(K) + 1
else :
    while cnt < K:
        i += 1
        if i//10 in lunlun_nums:
            num = list(map(int,[l for l in str(i)]))
            if abs(num[-2] - num[-1]) <= 1:
                lunlun_nums.append(i)
                cnt += 1
    output = i
print(output)