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: Runtime Error

Solution code:
import itertools
digits1 = [str(i) for i in range(1,10)]
digits2 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits1]))
digits3 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits2]))
digits4 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits3]))
digits5 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits4]))
digits6 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits5]))
digits7 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits6]))
digits8 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits7]))
digits9 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits8]))
digits10 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits9]))
index = digits1 + digits2 + digits3 + digits4 + digits5 + digits6 + digits7 + digits8 + digits9 + digits10
K = int(input())
print(index[K-1])

Submission status: Runtime Error

Solution code:
K = int(input())

list0 = ['0']
list1 = ['1']
list2 = ['2']
list3 = ['3']
list4 = ['4']
list5 = ['5']
list6 = ['6']
list7 = ['7']
list8 = ['8']
list9 = ['9']

an = 0


def AAA(list0,list1,list2,list3,list4,list5,list6,list7,list8,list9):
    nlist0 = [0]*(len(list0)+len(list1))
    nlist1 = [0]*(len(list0)+len(list1)+len(list2))
    nlist2 = [0]*(len(list1)+len(list2)+len(list3))
    nlist3 = [0]*(len(list2)+len(list3)+len(list4))
    nlist4 = [0]*(len(list3)+len(list4)+len(list5))
    nlist5 = [0]*(len(list4)+len(list5)+len(list6))
    nlist6 = [0]*(len(list5)+len(list6)+len(list7))
    nlist7 = [0]*(len(list6)+len(list7)+len(list8))
    nlist8 = [0]*(len(list7)+len(list8)+len(list9))
    nlist9 = [0]*(len(list8)+len(list9))
    
    for i in range(len(list0)):
        nlist0[i] = '0' + list0[i]
    for j in range(len(list1)):
        nlist0[len(list0)+j] = '0' + list1[j]
        
        
    for i in range(len(list0)):
        nlist1[i] = '1' + list0[i]
    for j in range(len(list1)):
        nlist1[len(list0)+j] = '1' + list1[j]
    for k in range(len(list2)):
        nlist1[len(list0)+len(list1)+k] = '1' + list2[k]
        
    
    for i in range(len(list1)):
        nlist2[i] = '2' + list1[i]
    for j in range(len(list2)):
        nlist2[len(list1)+j] = '2' + list2[j]
    for k in range(len(list3)):
        nlist2[len(list1)+len(list2)+k] = '2' + list3[k]
        

    for i in range(len(list2)):
        nlist3[i] = '3' + list2[i]
    for j in range(len(list3)):
        nlist3[len(list2)+j] = '3' + list3[j]
    for k in range(len(list4)):
        nlist3[len(list2)+len(list3)+k] = '3' + list4[k]
    
    for i in range(len(list3)):
        nlist4[i] = '4' + list3[i]
    for j in range(len(list4)):
        nlist4[len(list3)+j] = '4' + list4[j]
    for k in range(len(list5)):
        nlist4[len(list3)+len(list4)+k] = '4' + list5[k]
    
    for i in range(len(list4)):
        nlist5[i] = '5' + list4[i]
    for j in range(len(list5)):
        nlist5[len(list4)+j] = '5' + list5[j]
    for k in range(len(list6)):
        nlist5[len(list4)+len(list5)+k] = '5' + list6[k]
    
    for i in range(len(list5)):
        nlist6[i] = '6' + list5[i]
    for j in range(len(list6)):
        nlist6[len(list5)+j] = '6' + list6[j]
    for k in range(len(list7)):
        nlist6[len(list5)+len(list6)+k] = '6' + list7[k]
    
    for i in range(len(list6)):
        nlist7[i] = '7' + list6[i]
    for j in range(len(list7)):
        nlist7[len(list6)+j] = '7' + list7[j]
    for k in range(len(list8)):
        nlist7[len(list6)+len(list7)+k] = '7' + list8[k]
    
    for i in range(len(list7)):
        nlist8[i] = '8' + list7[i]
    for j in range(len(list8)):
        nlist8[len(list7)+j] = '8' + list8[j]
    for k in range(len(list9)):
        nlist8[len(list7)+len(list8)+k] = '8' + list9[k]
    
    for i in range(len(list8)):
        nlist9[i] = '9' + list8[i]
    for j in range(len(list9)):
        nlist9[len(list8)+j] = '9' + list9[j]
        
    return(nlist0,nlist1,nlist2,nlist3,nlist4,nlist5,nlist6,nlist7,nlist8,nlist9)


while len(list1)+len(list2)+len(list3)+len(list4)+len(list5)+len(list6)+len(list7)+len(list8)+len(list9) < K:
    an = an + len(list1)+len(list2)+len(list3)+len(list4)+len(list5)+len(list6)+len(list7)+len(list8)+len(list9)
    list0,list1,list2,list3,list4,list5,list6,list7,list8,list9 = AAA(list0,list1,list2,list3,list4,list5,list6,list7,list8,list9)

nK = K - an
if len(list1) >= nK:
    ans = list1[nK-1]
    nK = 10**8
else:
    nK = nK - len(list1)

if len(list2) >= nK:
    ans = list2[nK-1]
    nK = 10**8
else:
    nK = nK - len(list2)

if len(list3) >= nK:
    ans = list3[nK-1]
    nK = 10**8
else:
    nK = nK - len(list3)

if len(list4) >= nK:
    ans = list4[nK-1]
    nK = 10**8
else:
    nK = nK - len(list4)

if len(list5) >= nK:
    ans = list5[nK-1]
    nK = 10**8
else:
    nK = nK - len(list5)

if len(list6) >= nK:
    ans = list6[nK-1]
    nK = 10**8
else:
    nK = nK - len(list6)
    
if len(list7) >= nK:
    ans = list7[nK-1]
    nK = 10**8
else:
    nK = nK - len(list7)

if len(list8) >= nK:
    ans = list8[nK-1]
    nK = 10**8
else:
    nK = nK - len(list8)

if len(list9) >= nK:
    ans = list9[nK-1]
    nK = 10**8
else:
    nK = nK - len(list9)
    
    
print(int(ans))

Submission status: Runtime Error

Solution code:
k = int(input())

i = 0
lun_ls = [1, 2, 3, 4, 5, 6, 7, 8, 9]
n = 0
while n < 9991:
  i += 1
  s = str(i)
  for j in range(len(s)-1):
    if (int(s[j]) - int(s[j+1])) not in [-1, 0, 1]:
      break
    else:
      lun_ls.append(i)
      n += 1

print(lun_ls[k-1])

Submission status: Runtime Error

Solution code:
k = int(input())

if 10 > k:
  print(k)
else:
  b = 9
  ans = 9
  while True:
    b +=1
    st=str(b)
    for i in range(len(st)-1):
      if abs(int(st[i])-int(st[i+1])) > 1:
        break
    else:
      ans +=1
      
    if ans == k:
      break
print(b)

Submission status: Runtime Error

Solution code:
def solve():
  k = int(input())
  list = [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, 332, 333, 334, 343, 344, 345, 432, 433, 434, 443, 444, 445, 454, 455, 456, 543, 544, 545, 554, 555, 556, 565, 566, 567, 654, 655, 656, 665, 666, 667, 676, 677, 678, 765, 766, 767, 776, 777, 778, 787, 788, 789, 876, 877, 878, 887, 888, 889, 898, 899, 987, 988, 989, 998, 999, 1000, 1001, 1010, 1011, 1012, 1100, 1101, 1110, 1111, 1112, 1121, 1122, 1123, 1210, 1211, 1212, 1221, 1222, 1223, 1232, 1233, 1234, 2100, 2101, 2110, 2111, 2112, 2121, 2122, 2123, 2210, 2211, 2212, 2221, 2222, 2223, 2232, 2233, 2234, 2321, 2322, 2323, 2332, 2333, 2334, 2343, 2344, 2345, 3210, 3211, 3212, 3221, 3222, 3223, 3232, 3233, 3234, 3321, 3322, 3323, 3332, 3333, 3334, 3343, 3344, 3345, 3432, 3433, 3434, 3443, 3444, 3445, 3454, 3455, 3456, 4321, 4322, 4323, 4332, 4333, 4334, 4343, 4344, 4345, 4432, 4433, 4434, 4443, 4444, 4445, 4454, 4455, 4456, 4543, 4544, 4545, 4554, 4555, 4556, 4565, 4566, 4567, 5432, 5433, 5434, 5443, 5444, 5445, 5454, 5455, 5456, 5543, 5544, 5545, 5554, 5555, 5556, 5565, 5566, 5567, 5654, 5655, 5656, 5665, 5666, 5667, 5676, 5677, 5678, 6543, 6544, 6545, 6554, 6555, 6556, 6565, 6566, 6567, 6654, 6655, 6656, 6665, 6666, 6667, 6676, 6677, 6678, 6765, 6766, 6767, 6776, 6777, 6778, 6787, 6788, 6789, 7654, 7655, 7656, 7665, 7666, 7667, 7676, 7677, 7678, 7765, 7766, 7767, 7776, 7777, 7778, 7787, 7788, 7789, 7876, 7877, 7878, 7887, 7888, 7889, 7898, 7899, 8765, 8766, 8767, 8776, 8777, 8778, 8787, 8788, 8789, 8876, 8877, 8878, 8887, 8888, 8889, 8898, 8899, 8987, 8988, 8989, 8998, 8999, 9876, 9877, 9878, 9887, 9888, 9889, 9898, 9899, 9987, 9988, 9989, 9998, 9999, 10000, 10001, 10010, 10011, 10012, 10100, 10101, 10110, 10111, 10112, 10121, 10122, 10123, 11000, 11001, 11010, 11011, 11012, 11100, 11101, 11110, 11111, 11112, 11121, 11122, 11123, 11210, 11211, 11212, 11221, 11222, 11223, 11232, 11233, 11234, 12100, 12101, 12110, 12111, 12112, 12121, 12122, 12123, 12210, 12211, 12212, 12221, 12222, 12223, 12232, 12233, 12234, 12321, 12322, 12323, 12332, 12333, 12334, 12343, 12344, 12345, 21000, 21001, 21010, 21011, 21012, 21100, 21101, 21110, 21111, 21112, 21121, 21122, 21123, 21210, 21211, 21212, 21221, 21222, 21223, 21232, 21233, 21234, 22100, 22101, 22110, 22111, 22112, 22121, 22122, 22123, 22210, 22211, 22212, 22221, 22222, 22223, 22232, 22233, 22234, 22321, 22322, 22323, 22332, 22333, 22334, 22343, 22344, 22345, 23210, 23211, 23212, 23221, 23222, 23223, 23232, 23233, 23234, 23321, 23322, 23323, 23332, 23333, 23334, 23343, 23344, 23345, 23432, 23433, 23434, 23443, 23444, 23445, 23454, 23455, 23456, 32100, 32101, 32110, 32111, 32112, 32121, 32122, 32123, 32210, 32211, 32212, 32221, 32222, 32223, 32232, 32233, 32234, 32321, 32322, 32323, 32332, 32333, 32334, 32343, 32344, 32345, 33210, 33211, 33212, 33221, 33222, 33223, 33232, 33233, 33234, 33321, 33322, 33323, 33332, 33333, 33334, 33343, 33344, 33345, 33432, 33433, 33434, 33443, 33444, 33445, 33454, 33455, 33456, 34321, 34322, 34323, 34332, 34333, 34334, 34343, 34344, 34345, 34432, 34433, 34434, 34443, 34444, 34445, 34454, 34455, 34456, 34543, 34544, 34545, 34554, 34555, 34556, 34565, 34566, 34567, 43210, 43211, 43212, 43221, 43222, 43223, 43232, 43233, 43234, 43321, 43322, 43323, 43332, 43333, 43334, 43343, 43344, 43345, 43432, 43433, 43434, 43443, 43444, 43445, 43454, 43455, 43456, 44321, 44322, 44323, 44332, 44333, 44334, 44343, 44344, 44345, 44432, 44433, 44434, 44443, 44444, 44445, 44454, 44455, 44456, 44543, 44544, 44545, 44554, 44555, 44556, 44565, 44566, 44567, 45432, 45433, 45434, 45443, 45444, 45445, 45454, 45455, 45456, 45543, 45544, 45545, 45554, 45555, 45556, 45565, 45566, 45567, 45654, 45655, 45656, 45665, 45666, 45667, 45676, 45677, 45678, 54321, 54322, 54323, 54332, 54333, 54334, 54343, 54344, 54345, 54432, 54433, 54434, 54443, 54444, 54445, 54454, 54455, 54456, 54543, 54544, 54545, 54554, 54555, 54556, 54565, 54566, 54567, 55432, 55433, 55434, 55443, 55444, 55445, 55454, 55455, 55456, 55543, 55544, 55545, 55554, 55555, 55556, 55565, 55566, 55567, 55654, 55655, 55656, 55665, 55666, 55667, 55676, 55677, 55678, 56543, 56544, 56545, 56554, 56555, 56556, 56565, 56566, 56567, 56654, 56655, 56656, 56665, 56666, 56667, 56676, 56677, 56678, 56765, 56766, 56767, 56776, 56777, 56778, 56787, 56788, 56789, 65432, 65433, 65434, 65443, 65444, 65445, 65454, 65455, 65456, 65543, 65544, 65545, 65554, 65555, 65556, 65565, 65566, 65567, 65654, 65655, 65656, 65665, 65666, 65667, 65676, 65677, 65678, 66543, 66544, 66545, 66554, 66555, 66556, 66565, 66566, 66567, 66654, 66655, 66656, 66665, 66666, 66667, 66676, 66677, 66678, 66765, 66766, 66767, 66776, 66777, 66778, 66787, 66788, 66789, 67654, 67655, 67656, 67665, 67666, 67667, 67676, 67677, 67678, 67765, 67766, 67767, 67776, 67777, 67778, 67787, 67788, 67789, 67876, 67877, 67878, 67887, 67888, 67889, 67898, 67899, 76543, 76544, 76545, 76554, 76555, 76556, 76565, 76566, 76567, 76654, 76655, 76656, 76665, 76666, 76667, 76676, 76677, 76678, 76765, 76766, 76767, 76776, 76777, 76778, 76787, 76788, 76789, 77654, 77655, 77656, 77665, 77666, 77667, 77676, 77677, 77678, 77765, 77766, 77767, 77776, 77777, 77778, 77787, 77788, 77789, 77876, 77877, 77878, 77887, 77888, 77889, 77898, 77899, 78765, 78766, 78767, 78776, 78777, 78778, 78787, 78788, 78789, 78876, 78877, 78878, 78887, 78888, 78889, 78898, 78899, 78987, 78988, 78989, 78998, 78999, 87654, 87655, 87656, 87665, 87666, 87667, 87676, 87677, 87678, 87765, 87766, 87767, 87776, 87777, 87778, 87787, 87788, 87789, 87876, 87877, 87878, 87887, 87888, 87889, 87898, 87899, 88765, 88766, 88767, 88776, 88777, 88778, 88787, 88788, 88789, 88876, 88877, 88878, 88887, 88888, 88889, 88898, 88899, 88987, 88988, 88989, 88998, 88999, 89876, 89877, 89878, 89887, 89888, 89889, 89898, 89899, 89987, 89988, 89989, 89998, 89999, 98765, 98766, 98767, 98776, 98777, 98778, 98787, 98788, 98789, 98876, 98877, 98878, 98887, 98888, 98889, 98898, 98899, 98987, 98988, 98989, 98998, 98999, 99876, 99877, 99878, 99887, 99888, 99889, 99898, 99899, 99987, 99988, 99989, 99998, 99999]
  print(list[k-1])
  return 0
 
if __name__ == "__main__":
  solve()

Submission status: Runtime Error

Solution code:
k = int(input())
def dfs(s):
  if len(s)<10:
    for i in range(-1, 2, 1):
      s+str(min(9, max(0, int(s[-1])+i)))
      return dfs(s)
  else:
    return s
S = []
for i in range(10):
  S.append(dfs(str(i)))

Submission status: Runtime Error

Solution code:
k=int(input())
if k==1:
  print(1)
  exit()
k=k-1
A=[[[1],[2],[3],[4],[5],[6],[7],[8],[9]]]+[[] for i in range(10)]
a=[-1,0,1]
B=[0]
for i in range(10):
  for j in A[i]:
    for s in range(3):
      if j[-1]==0 and s==0:
        continue
      if j[-1]==9 and s==2:
        continue
      A[i+1].append(j+[j[-1]+a[s]])
  B.append(B[-1]+len(A[i]))
i=0
while k>B[i]:
  i=i+1
for t in range(len(A[i-1][k-B[i-1]])):
  print(A[i-1][k-B[i-1]][t],end="")

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

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_run:
            lunlun.append(val)
        else:
            continue
        if len(lunlun) == k:
            end = True
            break
    if end:
        break

print(lunlun[k - 1])

Submission status: Runtime Error

Solution code:
K = input()
data = [int(i) for i in range(100000)]
data_lun = []
for j in data:
  word = [int(k) for k in data]
  sa = []
  for l in range(len(K)-1):
    sa.append(word[l+1]-word[l])
  if max(sa) == 1:
    data_lun.append(j)
print(j[int(K)-1])

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(100000000)
k = int(input())


def islunlun(l):
    for x in range(1,len(l)):
        if abs(ord(l[x])-ord(l[x-1])) > 1:
            return False
    return True

s = set()
mx = 3234566667
def generate(l):
    val = None
    if l == []:
        val = 0
    else:
        val = int("".join(list(map(str,l))))
    #print(l, val)
    if mx < val:
        return
    else:
        if l != []:
            s.add(val)
    if len(l) == 0:
        for x in range(1,10):
            l.append(x)
            generate(l.copy())
            l.pop(len(l)-1)
    else:
        #print(max(0, l[len(l) - 1] - 1), min(9,l[len(l)-1]+1)+1)
        for x in range(max(0,l[len(l)-1]-1), min(9,l[len(l)-1]+1)+1):
            l.append(x)
            generate(l)
            l.pop(len(l)-1)

"""def bt(l):
    for x in range(10):
        l.append()"""

generate([])
l = []
for x in s:
    l.append(x)
l.sort()
print(l[k-1])