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: Wrong Answer

Solution code:
def make_tree(G,keta,count):
    if keta==1:
        num =[]
        for i in range(1,10):
            count+=1
            if count ==k:
                print(i)
                exit()
            else:
                num.append(i)
        G.append(num)
        make_tree(G,2,count)
    else:
        
        num_list = G[keta-2]
        num_lis =[]
        for num in num_list:
            num_str = str(num)
            num_e = int(num_str[-1])
            if num_e == 0:
                count +=1
                if count == k :
                    print(int(num_str + "0"))
                    exit()
                num_lis.append(int((num_str)+"0"))
                count+=1
                if count == k :
                    print(int(num_str + "1"))
                    exit()
                num_lis.append(int((num_str)+"1"))
            elif num_e == 9:
                count +=1
                if count == k :
                    print(int(num_str + "8"))
                    exit()
                num_lis.append(int((num_str)+"8"))
                count+=1
                if count == k :
                    print(int(num_str + "8"))
                    exit()
                num_lis.append(int((num_str)+"8"))
            else:
                count +=1
                if count == k :
                    print(int(num_str + str(num_e-1)))
                    exit()
                num_lis.append(int(num_str + str(num_e-1)))
                count+=1
                if count == k :
                    print(int(num_str + str(num_e)))
                    exit()
                num_lis.append(int(num_str + str(num_e)))
                count+=1
                if count == k :
                    print(int(num_str + str(num_e+1)))
                    exit()
                num_lis.append(int(num_str + str(num_e+1)))
        G.append(num_lis)

        make_tree(G,keta+1,count)


k = int(input())
G=[]
make_tree(G,1,0)

Submission status: Wrong Answer

Solution code:
def check_rr(num):
  numstr = str(num)
  is_rr = True
  if(len(numstr) != 1):
    prev = 0
    for i,s in enumerate(numstr):
      if (i == 0):
        prev = int(s)
        continue
      
      if (abs(prev - int(s)) <= 1):
        continue
      else:
        is_rr = False
        break
  
  return is_rr

K = int(input())

count = 0
num = 1
while True:
  if(check_rr(num)):
    count += 1
    if (count == K):
      break
  num += 1
  
print(num)

Submission status: Wrong Answer

Solution code:
K = int(input())

def cal():
    count = 9
    d = [[1,2,3,4,5,6,7,8,9]]
    for i in range(10**9):
        d_ = []
        for j in range(len(d[i])):
            a = str(d[i][j])
            if a[-1]=="0":
                for k in [0,1]:
                    d_.append(int(a)*10+k)
                    count += 1
                    if K == count:
                        print(d_[-1])
                        return
            elif a[-1]=="9":
                for k in [8,9]:
                    d_.append(int(a)*10+k)
                    count += 1
                    if K == count:
                        print(d_[-1])
                        return 
            else:
                for k in [-1, 0, 1]:
                    d_.append(int(a)*10+int(a[-1])+k)
                    count += 1
                    if K == count:
                        print(d_[-1])
                        return
            d.append(d_)
if K <= 9:
    print(K)
else:
    cal()

Submission status: Wrong Answer

Solution code:
k=int(input())

l0=[1,2,3,4,5,6,7,8,9]
l1=[10,11,12,21,22,23,32,33,34,43,44,45,54,55,56,65,66,67,76,77,78,87,88,89,90,98,99]
l2=[]
l3=[]
l4=[]
l5=[]
l6=[]
l7=[]
l8=[]
l9=[]

for s in l1:
    temp=str(s)
    x=temp[-1]

    if x=="0":
        l2.append(int(temp+"0"))
        l2.append(int(temp+"1"))
        l2.append(int(temp+"9"))
    if x=="1":
        l2.append(int(temp+"0"))
        l2.append(int(temp+"1"))
        l2.append(int(temp+"2"))
    if x=="2":
        l2.append(int(temp+"1"))
        l2.append(int(temp+"2"))
        l2.append(int(temp+"3"))
    if x=="3":
        l2.append(int(temp+"2"))
        l2.append(int(temp+"3"))
        l2.append(int(temp+"4"))
    if x=="4":
        l2.append(int(temp+"3"))
        l2.append(int(temp+"4"))
        l2.append(int(temp+"5"))
    if x=="5":
        l2.append(int(temp+"4"))
        l2.append(int(temp+"5"))
        l2.append(int(temp+"6"))
    if x=="6":
        l2.append(int(temp+"5"))
        l2.append(int(temp+"6"))
        l2.append(int(temp+"7"))
    if x=="7":
        l2.append(int(temp+"6"))
        l2.append(int(temp+"7"))
        l2.append(int(temp+"8"))
    if x=="8":
        l2.append(int(temp+"7"))
        l2.append(int(temp+"8"))
        l2.append(int(temp+"9"))
    if x=="9":
        l2.append(int(temp+"0"))
        l2.append(int(temp+"8"))
        l2.append(int(temp+"9"))

for s in l2:
    temp=str(s)
    x=temp[-1]

    if x=="0":
        l3.append(int(temp+"0"))
        l3.append(int(temp+"1"))
        l3.append(int(temp+"9"))
    if x=="1":
        l3.append(int(temp+"0"))
        l3.append(int(temp+"1"))
        l3.append(int(temp+"2"))
    if x=="2":
        l3.append(int(temp+"1"))
        l3.append(int(temp+"2"))
        l3.append(int(temp+"3"))
    if x=="3":
        l3.append(int(temp+"2"))
        l3.append(int(temp+"3"))
        l3.append(int(temp+"4"))
    if x=="4":
        l3.append(int(temp+"3"))
        l3.append(int(temp+"4"))
        l3.append(int(temp+"5"))
    if x=="5":
        l3.append(int(temp+"4"))
        l3.append(int(temp+"5"))
        l3.append(int(temp+"6"))
    if x=="6":
        l3.append(int(temp+"5"))
        l3.append(int(temp+"6"))
        l3.append(int(temp+"7"))
    if x=="7":
        l3.append(int(temp+"6"))
        l3.append(int(temp+"7"))
        l3.append(int(temp+"8"))
    if x=="8":
        l3.append(int(temp+"7"))
        l3.append(int(temp+"8"))
        l3.append(int(temp+"9"))
    if x=="9":
        l3.append(int(temp+"0"))
        l3.append(int(temp+"8"))
        l3.append(int(temp+"9"))

for s in l3:
    temp=str(s)
    x=temp[-1]

    if x=="0":
        l4.append(int(temp+"0"))
        l4.append(int(temp+"1"))
        l4.append(int(temp+"9"))
    if x=="1":
        l4.append(int(temp+"0"))
        l4.append(int(temp+"1"))
        l4.append(int(temp+"2"))
    if x=="2":
        l4.append(int(temp+"1"))
        l4.append(int(temp+"2"))
        l4.append(int(temp+"3"))
    if x=="3":
        l4.append(int(temp+"2"))
        l4.append(int(temp+"3"))
        l4.append(int(temp+"4"))
    if x=="4":
        l4.append(int(temp+"3"))
        l4.append(int(temp+"4"))
        l4.append(int(temp+"5"))
    if x=="5":
        l4.append(int(temp+"4"))
        l4.append(int(temp+"5"))
        l4.append(int(temp+"6"))
    if x=="6":
        l4.append(int(temp+"5"))
        l4.append(int(temp+"6"))
        l4.append(int(temp+"7"))
    if x=="7":
        l4.append(int(temp+"6"))
        l4.append(int(temp+"7"))
        l4.append(int(temp+"8"))
    if x=="8":
        l4.append(int(temp+"7"))
        l4.append(int(temp+"8"))
        l4.append(int(temp+"9"))
    if x=="9":
        l4.append(int(temp+"0"))
        l4.append(int(temp+"8"))
        l4.append(int(temp+"9"))


for s in l4:
    temp=str(s)
    x=temp[-1]

    if x=="0":
        l5.append(int(temp+"0"))
        l5.append(int(temp+"1"))
        l5.append(int(temp+"9"))
    if x=="1":
        l5.append(int(temp+"0"))
        l5.append(int(temp+"1"))
        l5.append(int(temp+"2"))
    if x=="2":
        l5.append(int(temp+"1"))
        l5.append(int(temp+"2"))
        l5.append(int(temp+"3"))
    if x=="3":
        l5.append(int(temp+"2"))
        l5.append(int(temp+"3"))
        l5.append(int(temp+"4"))
    if x=="4":
        l5.append(int(temp+"3"))
        l5.append(int(temp+"4"))
        l5.append(int(temp+"5"))
    if x=="5":
        l5.append(int(temp+"4"))
        l5.append(int(temp+"5"))
        l5.append(int(temp+"6"))
    if x=="6":
        l5.append(int(temp+"5"))
        l5.append(int(temp+"6"))
        l5.append(int(temp+"7"))
    if x=="7":
        l5.append(int(temp+"6"))
        l5.append(int(temp+"7"))
        l5.append(int(temp+"8"))
    if x=="8":
        l5.append(int(temp+"7"))
        l5.append(int(temp+"8"))
        l5.append(int(temp+"9"))
    if x=="9":
        l5.append(int(temp+"0"))
        l5.append(int(temp+"8"))
        l5.append(int(temp+"9"))

for s in l5:
    temp=str(s)
    x=temp[-1]

    if x=="0":
        l6.append(int(temp+"0"))
        l6.append(int(temp+"1"))
        l6.append(int(temp+"9"))
    if x=="1":
        l6.append(int(temp+"0"))
        l6.append(int(temp+"1"))
        l6.append(int(temp+"2"))
    if x=="2":
        l6.append(int(temp+"1"))
        l6.append(int(temp+"2"))
        l6.append(int(temp+"3"))
    if x=="3":
        l6.append(int(temp+"2"))
        l6.append(int(temp+"3"))
        l6.append(int(temp+"4"))
    if x=="4":
        l6.append(int(temp+"3"))
        l6.append(int(temp+"4"))
        l6.append(int(temp+"5"))
    if x=="5":
        l6.append(int(temp+"4"))
        l6.append(int(temp+"5"))
        l6.append(int(temp+"6"))
    if x=="6":
        l6.append(int(temp+"5"))
        l6.append(int(temp+"6"))
        l6.append(int(temp+"7"))
    if x=="7":
        l6.append(int(temp+"6"))
        l6.append(int(temp+"7"))
        l6.append(int(temp+"8"))
    if x=="8":
        l6.append(int(temp+"7"))
        l6.append(int(temp+"8"))
        l6.append(int(temp+"9"))
    if x=="9":
        l6.append(int(temp+"0"))
        l6.append(int(temp+"8"))
        l6.append(int(temp+"9"))

for s in l6:
    temp=str(s)
    x=temp[-1]

    if x=="0":
        l7.append(int(temp+"0"))
        l7.append(int(temp+"1"))
        l7.append(int(temp+"9"))
    if x=="1":
        l7.append(int(temp+"0"))
        l7.append(int(temp+"1"))
        l7.append(int(temp+"2"))
    if x=="2":
        l7.append(int(temp+"1"))
        l7.append(int(temp+"2"))
        l7.append(int(temp+"3"))
    if x=="3":
        l7.append(int(temp+"2"))
        l7.append(int(temp+"3"))
        l7.append(int(temp+"4"))
    if x=="4":
        l7.append(int(temp+"3"))
        l7.append(int(temp+"4"))
        l7.append(int(temp+"5"))
    if x=="5":
        l7.append(int(temp+"4"))
        l7.append(int(temp+"5"))
        l7.append(int(temp+"6"))
    if x=="6":
        l7.append(int(temp+"5"))
        l7.append(int(temp+"6"))
        l7.append(int(temp+"7"))
    if x=="7":
        l7.append(int(temp+"6"))
        l7.append(int(temp+"7"))
        l7.append(int(temp+"8"))
    if x=="8":
        l7.append(int(temp+"7"))
        l7.append(int(temp+"8"))
        l7.append(int(temp+"9"))
    if x=="9":
        l7.append(int(temp+"0"))
        l7.append(int(temp+"8"))
        l7.append(int(temp+"9"))

for s in l7:
    temp=str(s)
    x=temp[-1]

    if x=="0":
        l8.append(int(temp+"0"))
        l8.append(int(temp+"1"))
        l8.append(int(temp+"9"))
    if x=="1":
        l8.append(int(temp+"0"))
        l8.append(int(temp+"1"))
        l8.append(int(temp+"2"))
    if x=="2":
        l8.append(int(temp+"1"))
        l8.append(int(temp+"2"))
        l8.append(int(temp+"3"))
    if x=="3":
        l8.append(int(temp+"2"))
        l8.append(int(temp+"3"))
        l8.append(int(temp+"4"))
    if x=="4":
        l8.append(int(temp+"3"))
        l8.append(int(temp+"4"))
        l8.append(int(temp+"5"))
    if x=="5":
        l8.append(int(temp+"4"))
        l8.append(int(temp+"5"))
        l8.append(int(temp+"6"))
    if x=="6":
        l8.append(int(temp+"5"))
        l8.append(int(temp+"6"))
        l8.append(int(temp+"7"))
    if x=="7":
        l8.append(int(temp+"6"))
        l8.append(int(temp+"7"))
        l8.append(int(temp+"8"))
    if x=="8":
        l8.append(int(temp+"7"))
        l8.append(int(temp+"8"))
        l8.append(int(temp+"9"))
    if x=="9":
        l8.append(int(temp+"0"))
        l8.append(int(temp+"8"))
        l8.append(int(temp+"9"))

for s in l8:
    temp=str(s)
    x=temp[-1]

    if x=="0":
        l9.append(int(temp+"0"))
        l9.append(int(temp+"1"))
        l9.append(int(temp+"9"))
    if x=="1":
        l9.append(int(temp+"0"))
        l9.append(int(temp+"1"))
        l9.append(int(temp+"2"))
    if x=="2":
        l9.append(int(temp+"1"))
        l9.append(int(temp+"2"))
        l9.append(int(temp+"3"))
    if x=="3":
        l9.append(int(temp+"2"))
        l9.append(int(temp+"3"))
        l9.append(int(temp+"4"))
    if x=="4":
        l9.append(int(temp+"3"))
        l9.append(int(temp+"4"))
        l9.append(int(temp+"5"))
    if x=="5":
        l9.append(int(temp+"4"))
        l9.append(int(temp+"5"))
        l9.append(int(temp+"6"))
    if x=="6":
        l9.append(int(temp+"5"))
        l9.append(int(temp+"6"))
        l9.append(int(temp+"7"))
    if x=="7":
        l9.append(int(temp+"6"))
        l9.append(int(temp+"7"))
        l9.append(int(temp+"8"))
    if x=="8":
        l9.append(int(temp+"7"))
        l9.append(int(temp+"8"))
        l9.append(int(temp+"9"))
    if x=="9":
        l9.append(int(temp+"0"))
        l9.append(int(temp+"8"))
        l9.append(int(temp+"9"))

l=l0+l1+l2+l3+l4+l5+l6+l7+l8+l9

print(l[k-1])

Submission status: Wrong Answer

Solution code:
from collections import deque
k = int(input())
que = deque(["1","2","3","4","5","6","7","8","9"])
c = 0
flag = True
visited = set()
res=[]
if k<=9:
    print(que[k])
else:
    while flag and len(que)!=0:
        n = len(que)
        for i in range(n):
            temp = que.popleft()
            res.append(temp)
            visited.add(temp)
            c+=1
            if int(int(temp[-1])-1)>=0:
                pot1 = str(temp) + str(int(int(temp[-1])-1))
                if pot1 not in visited:
                    que.append(pot1)
                    visited.add(pot1)
            pot2 = str(temp)+ str(temp[-1])
            
            if pot2 not in visited:
                que.append(pot2)
                visited.add(pot1)
            if int(temp[-1])==9:
                pass
            else:
                pot3 = temp+str(int(temp[-1])+1)
                if pot3 not in visited:
                    que.append(pot3)
                    visited.add(pot1)
            if c==k:
                flag = False
                break
    print(res[-1])

Submission status: Wrong Answer

Solution code:
def dp(i, j, memo):
    key = "{}.{}".format(i, j)

    if i == 1:
        memo[key] = 1
        return memo[key]

    if key in memo:
        return memo[key]

    if j == 0:
        memo[key] = dp(i-1, j, memo) + dp(i-1, j+1, memo)
        return memo[key]

    if j == 9:
        memo[key] = dp(i-1, j-1, memo) + dp(i-1, j, memo)
        return memo[key]

    memo[key] = dp(i-1, j-1, memo) + dp(i-1, j, memo) + dp(i-1, j+1, memo)
    return memo[key]

k = int(input())
memo = {"1.0": 0}

num = 0

i = 1
j = 0

while(num < k):
    j += 1
    j %= 10
    if j == 0:
        i += 1
    else:
        num += dp(i, j, memo)

p = k - num + dp(i, j, memo)
ans = [j]

for l in range(1, i):
    n = 0
    x = ans[-1] - 2
    while n < p and x < 10:
        x += 1
        n += dp(i-l, x, memo)
    ans.append(x)
    p = p - n + dp(i-l, x, memo)

print("".join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
K=int(input())
l=[]
cnt=0
def dfs(s, depth):
    if depth>8:
        return
    S=str(s)
    ls=int(S[-1])
    for i in range(max(0,ls-1),min(10,ls+2)):
        n=int(S+str(i))
        l.append(n)
        dfs(n, depth+1)
for i in range(1, 10):
    dfs(i, 0)
l.sort()
print(l[K])

Submission status: Wrong Answer

Solution code:
def main():
    k=int(input())
    l=[[] for _ in range(20)]
    l[1]=[0,1,2,3,4,5,6,7,8,9]
    cnt=9
    if cnt>=k:
        print(l[k])
        exit()
    for i in range(2,20):
        for keta in range(1,i):
            for j in l[keta]:
                f=j//10**(i-2)
                if j==0:
                    l[i].append(10**(i-1)+j)
                if f==0:
                    if j//10**(len(str(j))-1)==1:
                        l[i].append(10**(i-1)+j)
                elif f==1:
                    l[i].append(10**(i-1)+j)
                    l[i].append(2*10**(i-1)+j)
                elif f==9:
                    l[i].append(8*10**(i-1)+j)
                    l[i].append(9*10**(i-1)+j)
                elif f>0:
                    l[i].append((f-1)*10**(i-1)+j)
                    l[i].append(f*10**(i-1)+j)
                    l[i].append((f+1)*10**(i-1)+j)
        if cnt+len(l[i])>=k:
            l[i].sort()
            ans=l[i][k-cnt-1]
            if ans==0:
                print(10**(i-1))
            else:
                print(ans)
            exit()
        else:
            cnt+=len(l[i])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def isLun(n):
    n = list(map(int, list(str(n))))
    l = [abs(n[i+1]-n[i]) for i in range(len(n)-1)]
    if set(l) == set([1]) or set(l) == set([0]) or len(n)==1:
        return True
    else:
        return False

n = int(input())
lun, ctr, i = 1, 1, 1
while ctr<=n:
    if isLun(i):
        lun=i
        ctr+=1
    i+=1
print(lun)

Submission status: Wrong Answer

Solution code:
k = int(input())

ans = 1
cnt = 0
while cnt < k:
    # print(ans, cnt)
    if ans <= 9:
        cnt+=1
        ans+=1
        continue
    li = list(map(int, list(str(ans))))
    for i in range(len(li)-1):
        if abs(li[i]-li[i+1]) > 1:
            ans+=1
            break
        cnt+=1
        ans += 1
print(ans-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
K = int(input())
count = 0
a = 1

while count != K:
    b= np.array([int(i) for i in str(a)])
    diff = np.diff(b)
    if np.all(diff<2):
        count += 1
    a += 1

print(a)

Submission status: Wrong Answer

Solution code:
k = int(input())


def recur(num):
    i = int(str(num)[0])
    lst = filter(lambda x: 0 < x and x < 10, [i-1, i, i + 1])
    return list(map(lambda x: int("{}{}".format(x, num)), lst))


lst = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
last = lst
while True:
    if (len(lst)-1) >= k:
        print(lst[k])
        break
    new_digits = []
    for last_i in last:
        new_digits.extend(recur(last_i))
    new_digits.sort()
    lst.extend(new_digits)
    last = new_digits

Submission status: Wrong Answer

Solution code:
k = int(input())
ans = 0
A = [1,2,3,4,5,6,7,8,9]
B = [3234566667]
if k < 10:
  print(k)
  exit()
k = k - 9
if k > 50000:
    ans = 100000
    for i in range(3234566667,0,-1):
        a= list(str(i))
        for j in range(len(a)-1):
            if abs(int(a[j]) - int(a[j+1])) > 1:
                break
            ans -= 1
            B.append(i)
            if ans == k:
              print(min(B))
              exit()
else:
    for i in range(10000000000):
        a= list(str(i))
        for j in range(len(a)-1):
            if abs(int(a[j]) - int(a[j+1])) > 1:
                break
            ans += 1
            A.append(i)
            if ans == k:
              print(max(A))
              exit()

Submission status: Wrong Answer

Solution code:
k = int(input())
if k < 10:
	print(k)
else:
	dp = [[0 for _ in range(10)] for _ in range(30)] #確認
	for i in range(10):
		dp[1][i] = 1
	for i in range(2, 30):
		for j in range(10):
			if j == 0:
				dp[i][j] = dp[i-1][j] + dp[i-1][j+1]
			elif j == 9:
				dp[i][j] = dp[i-1][j] + dp[i-1][j-1]
			else:
				dp[i][j] = dp[i-1][j] + dp[i-1][j+1] + dp[i-1][j-1]

	#print(dp)
	cnt = 0
	for i in range(1, 30):
		for j in range(1, 10):
			cnt += dp[i][j]
			print(cnt)
			if cnt >= k:
				keta = i
				num = j
				break
		else:
			continue
		break

	left = k - cnt + dp[keta][num]


	ans = [num]
	while keta != 1:
		if num == 0:
			li = [0, 1]
		elif num == 9:
			li = [-1, 0]
		else:
			li = [-1, 0, 1]
		for i in li:
			print(li, i)
			if left > dp[keta-1][num+i]:
				left -= dp[keta-1][num+i]
			else:
				num += i
				ans.append(num)
				keta -= 1
				break
	ansl = []
	for i in range(len(ans)):
		ansl.append(str(ans[i]))
	anss = ''.join(ansl)
	print(anss)

Submission status: Wrong Answer

Solution code:
K = int(input())

from itertools import product
d = {}
num_list = []
for i in range(10):
    nums = set([min((i-1)%10, i), i, max((i+1)%10, i)])
#     nums = set([i, min(10-(i-1)%10, i),max((i+1)%10, i)])
    nums = [str(el) for el in nums]
    d[i] = list(product([str(i)], list(nums)))
    d[i] = [int(''.join(el)) for el in d[i]]
    d[i] = ['{:02}'.format(el) for el in d[i]]
    
    num_list.extend(d[i])
num_list = sorted(num_list)

def gen_2ll():
    count = 0
    ret = 0
    while int(ret)!=99:
        if int(ret)< 9 :
            ret += 1
            count += 1
            yield ret
        else:
            for i in range(1,10):
                for ret in d[i]:
                    count += 1
                    yield ret

ll2_list = list(gen_2ll())
                   
dd = [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}] # n桁目までのtopの値ごとのものを詰める

def get_ll(K):
    if K<=len(ll2_list):
        print(ll2_list[K-1])

get_ll(K)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
K = int(input())
queue = [str(i) for i in range(1, 10)]
# print(queue)
L = []
while queue:
    v = queue.pop(0)
    L.append(int(v))
    if v[-1] == "0":
        # print("v =", v)
        queue.append(v + v[-1])
        queue.append(v+"1")
        
    elif v[-1] == "9":
        # print("9", v)
        queue.append(v + "8")
        queue.append(v + v[-1])
    else:
        # print("else", v)
        t = int(v[-1])
        queue.append(v+str(t-1))
        queue.append(v+str(t+1))
        queue.append(v + v[-1])
    if len(L) >= K:
        break
L.sort()
# print()
# print(L[-39:])
print(L[K-1])

Submission status: Wrong Answer

Solution code:
K = int(input())
s = str(K)
n = 1



while K>0:
    f = True
    st = str(n)
    for i in range(len(st)-1):
        if abs(int(st[-i-1])-int(st[-i-2]))  <=1:

            continue
        else:
            f = False            
            n += 8*(10**(i))
            
            continue
    
    if f:
        K -= 1
        n+= 1

        
       

    

print(n-1)

Submission status: Wrong Answer

Solution code:
k = int(input())
ans = 0 #答え
i = 1 #数回す用
c = 0 #ルンルン数カウント

while c < k:
  j = str(i)
  if i < 13: #13未満なら
    c = c + 1 #ルンルン数
    print(c, i)
  else: #それ以外なら
    x = 0
    for n in range(len(j)-1): #ルンルン数判定を行う
      if abs(int(j[n]) - int(j[n+1])) > 1:#桁の差が1より大きかったら
        x = 1
        break
    if x == 0:
      c = c + 1
      print(c, i)
  i = i + 1 #iに1を足す

print(i-1)

Submission status: Wrong Answer

Solution code:
K = int(input())
ans = []
i = 1

while len(ans) < K :
  l = len(str(i)) - 1
  que = 'yes'
  for k in range(l):
    a = str(i)
    if abs( int(a[k])- int(a[k+1]) ) >= 2:
      que = 'no'
      break

  if que == 'yes':
    ans = ans + [i]


  i +=1

print(i)

Submission status: Wrong Answer

Solution code:
def main():
    k=int(input())
    l=[[] for _ in range(20)]
    l[1]=[0,1,2,3,4,5,6,7,8,9]
    cnt=9
    if cnt>=k:
        print(l[k])
        exit()
    for i in range(2,20):
        for keta in range(1,i):
            for j in l[keta]:
                f=j//10**(i-2)
                if j==0:
                    l[i].append(10**(i-1)+j)
                if f==0:
                    if j//10**(len(str(j))-1)==1:
                        l[i].append(10**(i-1)+j)
                elif f==1:
                    l[i].append(10**(i-1)+j)
                    l[i].append(2*10**(i-1)+j)
                elif f==9:
                    l[i].append(8*10**(i-1)+j)
                    l[i].append(9*10**(i-1)+j)
                elif f>0:
                    l[i].append((f-1)*10**(i-1)+j)
                    l[i].append(f*10**(i-1)+j)
                    l[i].append((f+1)*10**(i-1)+j)
            if cnt+len(l[i])>=k:
                l[i].sort()
                ans=l[i][k-cnt-1]
                if ans==0:
                    print(10**(i-1))
                else:
                    print(ans)
                exit()
            else:
                cnt+=len(l[i])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def f(n):
    C = [[1 for i in range(10)]]
    while sum(d for c in C for d in c[1:]) < n:
        C.append([sum(C[-1][max(0,i-1):min(i+2,10)]) for i in range(10)])
    return C

def solve():
    n = int(input())
    C = f(n)
    X = []
    m = sum(d for c in C[:-1] for d in c[1:])
    x = 1
    for x in range(1,10):
        if m + C[-1][x] < n:
            m += C[-1][x]
        else:
            break
    X.append(x)
    C = C[:-1]
    for c in C[::-1]:
        for x in range(max(0,X[-1]-1), min(9,X[-1]+2)):
            if m + c[x] < n:
                m += c[x]
            else:
                break
        X.append(x)
    return ''.join(map(str,X))


if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

Solution code:
def main():
    k=int(input())
    l=[[] for _ in range(20)]
    l[1]=[0,1,2,3,4,5,6,7,8,9]
    cnt=9
    if cnt>=k:
        print(l[k])
        exit()
    for i in range(2,20):
        for keta in range(1,i):
            for j in l[keta]:
                f=j//10**(i-2)
                if j==0:
                    l[i].append(10**(i-1)+j)
                if f==0:
                    if j//10**(len(str(j))-1)==1:
                        l[i].append(10**(i-1)+j)
                elif f==1:
                    l[i].append(10**(i-1)+j)
                    l[i].append(2*10**(i-1)+j)
                elif f==9:
                    l[i].append(8*10**(i-1)+j)
                    l[i].append(9*10**(i-1)+j)
                elif f>0:
                    l[i].append((f-1)*10**(i-1)+j)
                    l[i].append(f*10**(i-1)+j)
                    l[i].append((f+1)*10**(i-1)+j)
            if cnt+len(l[i])>=k:
                l[i].sort()
                ans=l[i][k-cnt-1]
                if ans==0:
                    print(10**(i-1))
                else:
                    l[4].sort()
                    print(l[4])
                    print(ans)
                exit()
            else:
                cnt+=len(l[i])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from math import sqrt
from collections import Counter, defaultdict

input = sys.stdin.readline


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    k = I()

    c = 0
    for i in range(99999999999):
        string = str(i)
        s0 = int(string[0])
        flag = True
        for s in string:
            ints = int(s)
            if abs(ints - s0) > 1:
                flag = False
                break
            s0 = ints
        if flag:
            c += 1
        if c == k:
            print(i)
            break

    pass


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
k = int(input())
number = 9

ans = 0
for i in range(10,10**5):
    check = 'OK'
    l = len(str(i))
    keta = list(str(i))
    for j in range(l-1):
        if abs(int(keta[j]) - int(keta[j+1])) <= 1:
            pass
        else:
            check = 'NG'
    if check == 'OK':
        number += 1
        if number == k:
            ans = i
            break
if k <= 9:
    print(k)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
K = int(input())

# dp[n][c] n 桁目が i　のときにルンルン数はいくつ？
dp = [[0] * 10 for _ in range(15)]

def f():
    for n in range(15):
        for i in range(10):
            if n == 5 and i > 1: return 0
            if n == 0:
                dp[n][i] = i
            elif i == 0:
                dp[n][i] = dp[n - 1][0] + dp[n - 1][1]
            elif i == 9:
                dp[n][i] = dp[n - 1][8] + dp[n - 1][9]
            else:
                dp[n][i] = dp[n - 1][i - 1] + dp[n - 1][i] + dp[n - 1][i + 1]
f()

def c(a):
    a = str(a)
    size = len(a)
    ctr = dp[size - 1][int(a[0])]
    a = list(map(int, a))
    for s in range(1, size):
        if max(a[s] + 1, a[s] - 1) < a[s - 1] + 1:
            start = max(a[s] + 1, a[s] - 1)
            end = a[s - 1] + 1
            for t in range(start, end):
                ctr -= dp[a[s]][t]
        else:
            return ctr
    return ctr


# または
ok = -1
ng = 3234566667 + 5

# これは上から抑えるか下から抑えるかで変わると思われる

while ng - ok > 1 :
    mid = (ok + ng) // 2
    a = c(mid)
    if a > K:
        ng = mid
    else :
        ok = mid

print(a)

Submission status: Wrong Answer

Solution code:
k = int(input())
if k < 10:
	print(k)
else:
	dp = [[0 for _ in range(10)] for _ in range(30)] #確認
	for i in range(10):
		dp[1][i] = 1
	for i in range(2, 30):
		for j in range(10):
			if j == 0:
				dp[i][j] = dp[i-1][j] + dp[i-1][j+1]
			elif j == 9:
				dp[i][j] = dp[i-1][j] + dp[i-1][j-1]
			else:
				dp[i][j] = dp[i-1][j] + dp[i-1][j+1] + dp[i-1][j-1]

	#print(dp)
	cnt = 0
	for i in range(1, 30):
		for j in range(1, 10):
			cnt += dp[i][j]
			#print(cnt)
			if cnt > k:
				keta = i
				num = j
				break
		else:
			continue
		break

	left = k - cnt + dp[keta][num]


	ans = [num]
	while keta != 1:
		if num == 0:
			li = [0, 1]
		elif num == 9:
			li = [-1, 0]
		else:
			li = [-1, 0, 1]
		for i in li:
			#print(li, i)
			if left > dp[keta-1][num+i]:
				left -= dp[keta-1][num+i]
			else:
				num += i
				ans.append(num)
				keta -= 1
				break
	ansl = []
	for i in range(len(ans)):
		ansl.append(str(ans[i]))
	anss = ''.join(ansl)
	print(anss)