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:
from collections import deque
K = int(input())
a = deque(range(1,10))
# a = deque()
pop_count = 0
while pop_count + len(a) < K:
    pop = a.popleft()
    pop_count +=1
    first_digit = pop % 10
    pull = pop * 10 + first_digit
    if first_digit != 9:
        a.extend([pull-1, pull, pull+1])
    else:
        a.extend([pull-1, pull])

print(a[K-pop_count-1])

Submission status: Wrong Answer

Solution code:
from itertools import product
K = int(input())

ans = []
for l in range(10):
    for s in range(1, 10):
        for pattern in product([-1, 0, 1], repeat=l):
            X = [s]
            for p in pattern:
                if not (0 <= X[-1] + p <= 9):
                    break
                X.append(X[-1] + p)
            else:
                ans.append(''.join(map(str, X)))

ans.sort()
print(ans[K - 1])

Submission status: Wrong Answer

Solution code:
k = int(input())
import collections
L = [1,2,3,4,5,6,7,8,9]
L = collections.deque(L)
#print(L)
cnt = 9
n =0
if k <=9:
    print(k)
    exit()
while n <=k:
    l = len(str(L[n]))
    i = int(str(L[n])[-1])
    if  i == 0:
        L.append(10**l)
        cnt +=1
        if cnt == k:
            print(10**l)
            exit()
        L.append(10**l+1)
        cnt +=1
        if cnt == k:
            print(10**l+1)
            exit()
    elif i == 9:
        L.append(i*10**(l)+8)
        cnt +=1
        if cnt == k:
            print(i*10**l+8)
            exit()
        L.append(i*10**(l)+9)
        cnt +=1
        if cnt == k:
            print(i*10**l+9)
            exit()
    else:
        L.append(i*10**(l)+i-1)
        cnt +=1
        if cnt == k:
            print(i*10**(l)+i-1)
            exit()
        L.append(i*10**(l)+i)
        cnt +=1
        if cnt == k:
            print(i*10**(l)+i)
            exit()
        L.append(i*10**(l)+i+1)
        cnt +=1
        if cnt == k:
            print(i*10**(l)+i+1)
            exit()

    n += 1

Submission status: Wrong Answer

Solution code:
a = [1,2,3,4,5,6,7,8,9,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000]
import heapq
heapq.heapify(a)
cnt = 19
c = 1
while True:
  if cnt > 10**5:
    break
  for i in a:
    if len(str(i)) == c:
      m = i//10**(c-1)
      if i//10**(c-1) == 1:
        heapq.heappush(a,i+10**c*(i//10**(c-1)))
        heapq.heappush(a,i+10**c*(i//10**(c-1)+1))
        cnt += 3
        for i in range(10-c):
          heapq.heappush(a,i+10**c*(10**(i+1)))
          cnt += 1
      elif i//10**(c-1) == 9:
        heapq.heappush(a,i+10**c*(i//10**(c-1)-1))
        heapq.heappush(a,i+10**c*(i//10**(c-1)))
        cnt += 2
      else:
        heapq.heappush(a,i+10**c*(i//10**(c-1)-1))
        heapq.heappush(a,i+10**c*(i//10**(c-1)))
        heapq.heappush(a,i+10**c*(i//10**(c-1)+1))
        cnt += 3
  c += 1

k = int(input())
for i in range(k-1):
  heapq.heappop(a)
print(heapq.heappop(a))

Submission status: Wrong Answer

Solution code:
a = [1,2,3,4,5,6,7,8,9,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000]
import heapq
heapq.heapify(a)
cnt = 18
c = 1
while True:
  if cnt > 10**5:
    break
  for i in a:
    if len(str(i)) == c:
      m = i//10**(c-1)
      if i//10**(c-1) == 1:
        heapq.heappush(a,i+10**c*(i//10**(c-1)))
        heapq.heappush(a,i+10**c*(i//10**(c-1)+1))
        cnt += 3
        for i in range(10-c):
          heapq.heappush(a,i+10**c*(10**(i+1)))
          cnt += 1
      elif i//10**(c-1) == 9:
        heapq.heappush(a,i+10**c*(i//10**(c-1)-1))
        heapq.heappush(a,i+10**c*(i//10**(c-1)))
        cnt += 2
      else:
        heapq.heappush(a,i+10**c*(i//10**(c-1)-1))
        heapq.heappush(a,i+10**c*(i//10**(c-1)))
        heapq.heappush(a,i+10**c*(i//10**(c-1)+1))
        cnt += 3
  c += 1

k = int(input())
for i in range(k-1):
  heapq.heappop(a)
print(heapq.heappop(a))

Submission status: Wrong Answer

Solution code:
import heapq

k = int(input())

lunlun = [1,2,3,4,5,6,7,8,9]
heapq.heapify(lunlun)

for i in range(1,10**5):
    x = heapq.heappop(lunlun) #最小値
    if i == k :
        break
    y = x % 10
    if y != 0:
         heapq.heappush(lunlun, x * 10 + y- 1)
    heapq.heappush(lunlun,10*x+y)
    if y != 9:
        heapq.heappush(lunlun, x * 10 + y + 1)
#print(lunlun)
print(x)

Submission status: Wrong Answer

Solution code:
import heapq

k = int(input())

lunlun = [1,2,3,4,5,6,7,8,9]
heapq.heapify(lunlun)

for i in range(1,10**5):
    x = heapq.heappop(lunlun) #最小値
    y = x % 10
    if i == k :
        break
    if y != 0:
         heapq.heappush(lunlun, x * 10 + y- 1)
    heapq.heappush(lunlun,10*x+y)
    if y != 9:
        heapq.heappush(lunlun, x * 10 + y + 1)
#print(lunlun)
print(x)

Submission status: Wrong Answer

Solution code:
import heapq

k = int(input())

lunlun = [1,2,3,4,5,6,7,8,9]
heapq.heapify(lunlun)

for i in range(1,10**5):
    x = heapq.heappop(lunlun) #最小値
    y = x % 10
    if i == k :
        break
    if y != 0:
         heapq.heappush(lunlun, x * 10 + y- 1)
    heapq.heappush(lunlun,10*x+y)
    if y != 9:
        heapq.heappush(lunlun, x * 10 + y + 1)
print(lunlun)
print(x)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
k = int(input())
a = []
for i in range(1, 10):
    a.append(i)
while True:
    if k <= len(a):
        print(a[k - 1])
        exit()
    k -= len(a)
    old = []
    a, old = old, a
    for x in old:
        for i in range(-1, 2):
            d = x % 10 + i
            if d < 0 and d > 9:
                continue
            nx = x * 10 + d
            a.append(nx)

Submission status: Wrong Answer

Solution code:
k = int(input())

from collections import deque
queue = deque(range(1,10))
count = 0
while count < k:
  count += 1
  tmp = queue.popleft()
  tail = tmp%10
  if tail != 0:
    queue.append(10*tmp+tail-1)
  queue.append(10*tmp)
  if tail != 9:
    queue.append(10*tmp+tail+1)

print(tmp)

Submission status: Wrong Answer

Solution code:
import collections
k=int(input())
if k<=9:
    print(k)
else:
    k-=9
    l =list(range(9,0,-1))
    print(l)
    q = collections.deque(l)
    counter=0
    while counter<k:
        x=q.pop()
        xrem=x%10
        if xrem!=0:
            q.appendleft(10*x+xrem-1)
            counter+=1
            if counter>=k:
                break
        q.appendleft(10*x+xrem)
        counter+=1
        if counter>=k:
                break
        if xrem!=9:
            q.appendleft(10*x+xrem+1)
            counter+=1
    print(q[0])

Submission status: Wrong Answer

Solution code:
from queue import Queue
K = int(input())
q = Queue()
for i in range(1,10):
    q.put(i)

cnt = 9
ans = 0
while True:
    l = q.get()
    end = l % 10
    for i in range(-1,2):
        i += end
        if 0 <= i <= 9:
            q.put(l*10+i)
            cnt += 1
            if cnt == K:
                ans = l*10+i

    if cnt >= K:
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
from collections import deque
K=int(input())
d=deque([_ for _ in range(1,10)])
if K<=9:
  print(K)
  exit()
i=0
while True:
  a=d.popleft()
  i+=1
  if i==K:
    print(a)
    exit()
  if a%10!=0 and a%10!=9:
    d.extend([10*a+(a%10)+i for i in range(-1,2)])
  elif a%10==0:
     d.extend([10*a+i for i in range(2)])
  else:
     d.extend([10*a+i for i in range(-1,2)])

Submission status: Wrong Answer

Solution code:
from collections import deque
K=int(input())
d=deque([_ for _ in range(1,10)])
if K<=9:
  print(K)
  exit()
i=0
while True:
  a=d.pop()
  i+=1
  if i==K:
    print(a)
    exit()
  if a%10!=0 and a%10!=9:
    d.extend([10*a+(a%10)+i for i in range(-1,2)])
  elif a%10==0:
     d.extend([10*a+i for i in range(2)])
  else:
     d.extend([10*a+i for i in range(-1,2)])

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

queue = list(range(1,10))

for i in range(15):
  lunlun = queue.pop(0)
  #print(lunlun)
  last = lunlun%10
  if last!=0:
    queue.append(10*lunlun+last-1)
  queue.append(10*lunlun+last)
  if last!=9:
    queue.append(10*lunlun+last+1)

print(lunlun)

Submission status: Wrong Answer

Solution code:
K = int(input())

Queue = []

for n in range(1,10):
    Queue.append(n)

for n in range(0,K):
    x = Queue.pop(n)
    if x % 10 != 0:
        Queue.append(10*x-1)
    Queue.append(10 * x)
    if x % 10 != 9:
        Queue.append(10*x+1)

print(x)

Submission status: Wrong Answer

Solution code:
k = int(input())
anss = [1,2,3,4,5,6,7,8,9]
for i in range(12):
    if len(anss) > k:
        print(anss[k-1])
        break
    new_anss = []
    for ans in anss:
        if ans % 10 != 0:
            new_anss += [ans*10+ans-1]
        new_anss += [ans*10+ans]
        if ans % 10 != 9:
            new_anss += [ans*10+ans+1]
    k -= len(anss)
    anss = new_anss

Submission status: Wrong Answer

Solution code:
from collections import deque
K = int(input()) - 1
todo = deque(range(1, 10))
ans = []
counter = 0
while counter <= K:
    seed = todo.pop()
    ans.append(seed)
    counter += 1
    last_dig = int(str(seed)[-1])
    for i in range(max(0, last_dig-1), min(10, last_dig+2)):
        todo.append(int(str(seed) + str(i)))
print(ans[-1])

Submission status: Wrong Answer

Solution code:
k=int(input());l=list(range(1,10))
for i in l:
  if len(l)==k: print(i); break
  for j in range(max(i%10-1,0),min(i%10+2,10)): l+=[i*10+j]

Submission status: Wrong Answer

Solution code:
k=int(input())
 
from collections import deque
q = deque(range(1, 10))

for i in range(k-1):
    d = q.popleft()
    if d % 10 != 0:
        q.append(10 * d + d % 10 - 1)
    q.append(10*d)
    if d % 10 != 9:
        q.append(10 * d + d % 10 +1)
    
print(q.popleft())

Submission status: Wrong Answer

Solution code:
k=int(input())
 
from collections import deque
q = deque(range(1, 10))

for i in range(k-1):
    d = q.popleft()
    if d % 10 != 0:
        q.append(10*d-1)
    q.append(10*d)
    if d % 10 != 9:
        q.append(10*d+1)
    
print(q.popleft())

Submission status: Wrong Answer

Solution code:
K = int(input())
lunlun = [n for n in range(10)]
if K < 10:
    print(K)
else:
    tmp = 9
    pre_top = 1
    pre_bottom = 9
    while(1):
        for j in range(pre_top, pre_bottom+1):
            for k in range(10):
                if abs(lunlun[j]%10 - k) < 2:
                    lunlun.append(lunlun[j]*10+k)
                    tmp += 1
                    if tmp == K:
                        break
            if tmp == K:
                break
        pre_top = pre_bottom + 1
        pre_bottom = tmp
        if tmp == K:
            break

print(lunlun[-1])

Submission status: Wrong Answer

Solution code:
def func(n):
    if (n==0):return [n,n+1]
    if (n==9):return [n-1,n]
    return [n-1,n,n+1]
k = int(input())
k_su = 0
lunlun_fl = [1,2,3,4,5,6,7,8,9]
while True:
    k_su += 1
    lunlun_fl_ = lunlun_fl
    #print('{} 桁目探索開始'.format(k_su+1))
    for i in lunlun_fl_:
        if (len(str(i)) != k_su):
            continue
        lunlun_n = list(map(lambda x:int(str(i)+str(x)),func(int(str(i)[-1]))))
        lunlun_fl.extend(lunlun_n)
        if (len(lunlun_fl) >= k):break
    #print(lunlun_fl)
    if (len(lunlun_fl) >= k):break
print(lunlun_fl[-1])

Submission status: Wrong Answer

Solution code:
k=int(input())

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


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

    if x==0:
        #l0.append(int(temp+"0"))
        l0.append(int(temp+"1"))
        l0.append(int(temp+"9"))
    if x>=1 and x<=8:
        l0.append(int(temp+str(x-1)))
        l0.append(int(temp+str(x)))
        l0.append(int(temp+str(x+1)))
    if x==9:
        #l0.append(int(temp+"0"))
        l0.append(int(temp+"8"))
        l0.append(int(temp+"9"))
    
    if len(l0)>100002:
        break
l0.sort()

print(l0[k-1])

Submission status: Wrong Answer

Solution code:
k=int(input())

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


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

    if x==0:
        #l0.append(int(temp+"0"))
        l0.append(int(temp+"1"))
        l0.append(int(temp+"9"))
    if x>=1 and x<=8:
        l0.append(int(temp+str(x-1)))
        l0.append(int(temp+str(x)))
        l0.append(int(temp+str(x+1)))
    if x==9:
        #l0.append(int(temp+"0"))
        l0.append(int(temp+"8"))
        l0.append(int(temp+"9"))
    
    if len(l0)>100000:
        break
l0.sort()

print(l0[k-1])

Submission status: Wrong Answer

Solution code:
k=int(input())

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


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

    if x==0:
        l0.append(int(temp+"0"))
        l0.append(int(temp+"1"))
        l0.append(int(temp+"9"))
    if x>=1 and x<=8:
        l0.append(int(temp+str(x-1)))
        l0.append(int(temp+str(x)))
        l0.append(int(temp+str(x+1)))
    if x==9:
        l0.append(int(temp+"0"))
        l0.append(int(temp+"8"))
        l0.append(int(temp+"9"))
    
    if len(l0)>100000:
        break

print(l0[k-1])

Submission status: Wrong Answer

Solution code:
k=int(input())

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


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

    if x==0:
        l0.append(int(temp+"0"))
        l0.append(int(temp+"1"))
        l0.append(int(temp+"9"))
    if x>=1 and x<=8:
        l0.append(int(temp+str(x-1)))
        l0.append(int(temp+str(x)))
        l0.append(int(temp+str(x+1)))
    if x=="9":
        l0.append(int(temp+"0"))
        l0.append(int(temp+"8"))
        l0.append(int(temp+"9"))
    
    if len(l0)>100000:
        break
l0.sort()

print(l0[k-1])

Submission status: Wrong Answer

Solution code:
lun_luns = [1, 2, 3, 4, 5, 6, 7, 8, 9]
k = int(input())
index = 0
while True:
	if len(lun_luns) >= k:
		break
	num = lun_luns[index]
	mod = num % 10
	n = num * 10
	if mod == 9:
		lun_luns.extend([n+mod-1, n+mod])
	else:
		lun_luns.extend([n+mod-1, n+mod, n+mod+1])
	index += 1
print(lun_luns[k-1])

Submission status: Wrong Answer

Solution code:
lun_luns = [1, 2, 3, 4, 5, 6, 7, 8, 9]
k = int(input())
index = 0
while True:
	if len(lun_luns) >= k:
		break
	num = lun_luns.pop(index)
	lun_luns.insert(index, num)
	mod = num % 10
	n = num * 10
	if mod == 9:
		lun_luns.extend([n+mod-1, n+mod])
	else:
		lun_luns.extend([n+mod-1, n+mod, n+mod+1])
	index += 1
print(lun_luns[k-1])

Submission status: Wrong Answer

Solution code:
K=int(input())
ans=9
dp=[[0]*10 for i in range(10)]
dp[0]=[1]*10
flag=0
index,r=0,0
for j in range(1,10):
    for i in range(10):
        tmp=0
        tmp+=dp[j-1][i]
        if i-1>=0:
            tmp+=dp[j-1][i-1]
        if i+1<=9:
            tmp+=dp[j-1][i+1]
        dp[j][i]=tmp
        if i!=0:
            ans+=dp[j][i]
        if ans>=K:
            index,r=j,i
            flag=1
            break
    if flag==1:
        break
print(dp)
print(index,r)
K-=ans
ans=r*10**(index)
K=abs(K)
print(K)
for i in range(index-1,-1,-1):
    for j in range(10):
        if K-dp[i][j]>0:
            K-=dp[i][j]
        elif K-dp[i][j]==0:
            ans+=j*10**(i+1)
            print(ans)
            print(exit())
        else:
            K+=dp[i][j]
            ans+=(j)*10**(i)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    K = ii()
    q = [1, 2, 3, 4, 5, 6, 7, 8, 9]

    for k in range(K - 1):
        x = q.pop(0)
        mod = x % 10
        if mod == 0:
            q.append(10 * x)
            q.append(10 * x + 1)
        elif mod == 9:
            q.append(10 * x - 1)
            q.append(10 * x)
        else:
            q.append(10 * x + mod - 1)
            q.append(10 * x + mod)
            q.append(10 * x + mod + 1)

    print(q[0])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# 解説放送
k = int(input())
a = [i+1 for i in range(9)]


while 1:
    if k <= len(a):
        print(a[k-1])
        exit()
    k -= len(a)
    old = []
    a, old = old, a
    for x in old:
        for i in range(-1, 2):
            d = x % 10 + i
            if d < 0 or d > 9: continue
            nx = x*10 + d
            a.append(nx)
    print(a)

Submission status: Wrong Answer

Solution code:
k = int(input())
 
qu = list(range(1,10))
 
cnt = 0
while( cnt < k ):
  out = qu.pop(0)
  r = out%10
  y = 10*out+r
  if( r != 0 ):
    qu.append(y-1)
  qu.append(y+r)
  
  if( r!=9):
    qu.append(y+1)
  cnt+=1
    
print(out)

Submission status: Wrong Answer

Solution code:
from collections import deque
a=int(input())
q=deque([1,2,3,4,5,6,7,8,9])
def dfs(k):
  while k<=a:
    s=q.popleft()
    if s-1>=0:
      q.append(s*10+s-1)
      k=k+1
      if k==a:
        print(q.pop())
    q.append(s*10+s)
    k=k+1
    if k==a:
        print(q.pop())
    if s+1<=9:
      q.append(s*10+s+1)
      k=k+1
      if k==a:
        print(q.pop())
  
 
if a<=9:
  print(a)
else:
  dfs(9)

Submission status: Wrong Answer

Solution code:
from collections import deque
a=int(input())
q=deque([1,2,3,4,5,6,7,8,9])
def dfs(k):
  while k<=a:
    s=q.popleft()
    if s-1>=0:
      q.append(s*10+s-1)
      k=k+1
      if k==a:
        print(q.pop())
    q.append(s*10+s)
    k=k+1
    if k==a:
        print(q.pop())
    if s+1<=9:
      q.append(s*10+s+1)
      k=k+1
      if k==a:
        print(q.pop())
  
 
if a<=9:
  print(a)
else:
  dfs(9)

Submission status: Wrong Answer

Solution code:
k = int(input())

def calc_dp(n):
    if(n==0):
        return 0

    s = str(n)
    slen = len(s)
    dp = [[0] * 12 for _ in range(slen)]
    dp_o = [[0] * 12 for _ in range(slen)]

    #initial
    for i in range(1,int(s[0])):
        dp[0][i+1] = 1
    dp_o[0][int(s[0])+1] = 1

    #update
    for i in range(slen-1):
        for j in range(1,11):
            dp[i+1][j] = dp[i][j-1] + dp[i][j] + dp[i][j+1] +1
        dp[i+1][1] -= 1

        s_b = int(s[i])
        s_n = int(s[i+1])
        for j in range( max(0,s_b-1), min(9, s_b+2)  ):
            if(j < s_n ):
                dp[i+1][j+1] += dp_o[i][s_b+1]
            elif(j == s_n):
                dp_o[i+1][j+1] += dp_o[i][s_b+1]

    ans = 0
    for i in range(1,11):
        ans += dp[-1][i] + dp_o[-1][i]

    return ans

min_ = 0
max_ = 3234566676


for i in range(100):
    tmp = (min_+max_)//2
    tmp_c = calc_dp(tmp)
    if(k > tmp_c):
        min_ = tmp
    else:
        max_ = tmp

    if(max_ - min_ == 1 ):
        break

print(max_)

Submission status: Wrong Answer

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

K = int(input())
limit_list = []
upper_limit = 9
limit_list.append(upper_limit)
t_dict = {i: 1 for i in range(10)}
# 2桁目の場合
s_dict = {k: 3 for k in range(1, 9)}
s_dict[9] = 2
s_dict[0] = 2
upper_limit = upper_limit + sum(s_dict.values()) - s_dict[0]
limit_list.append(upper_limit)
ww_dict = {1: t_dict, 2: s_dict}  # 2桁目

i = 3
max_limit = 10 ** 5
while upper_limit <= max_limit:
    # 3桁目
    w_dict = {
        k: ww_dict[i - 1][k - 1] + ww_dict[i - 1][k] + ww_dict[i - 1][k]
        for k in range(1, 9)
    }
    w_dict[0] = ww_dict[i - 1][0] + ww_dict[i - 1][1]
    w_dict[9] = ww_dict[i - 1][8] + ww_dict[i - 1][9]
    ww_dict[i] = w_dict
    upper_limit = limit_list[-1] + sum(w_dict.values()) - w_dict[0]
    limit_list.append(upper_limit)
    i += 1

# K = 208644

for i, l in enumerate(limit_list):
    if l >= K:
        keta = i + 1
        break

keta_list = list(range(1, keta + 1))

ans_list = []

# i-1桁目のMAX値
t = limit_list[keta - 2]

if keta == 1:
    ans_list = [K]
else:
    for i in keta_list[::-1]:
        # i桁目の数字を決めたい
        if i == keta_list[-1]:
            # iが最大桁の場合の候補の数字
            number_list = list(range(1, 10))
        else:
            if ans_list[-1] == 9:
                max_n = 9
            else:
                max_n = ans_list[-1] + 1
            min_n = 0 if ans_list[-1] == 0 else ans_list[-1] - 1
            number_list = list(range(min_n, max_n + 1))
        for n in number_list:
            if i == 1:
                w = t + 1
            else:
                w = t + ww_dict[i][n]
            if w >= K:
                ans_list.append(n)
                break
            # 超えていなかったら更新
            t = w

ans = "".join([str(i) for i in ans_list])
print(ans)

Submission status: Wrong Answer

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

K = int(input())
limit_list = []
upper_limit = 9
limit_list.append(upper_limit)
t_dict = {i: 1 for i in range(10)}
# 2桁目の場合
s_dict = {k: 3 for k in range(1, 9)}
s_dict[9] = 2
s_dict[0] = 2
upper_limit = upper_limit + sum(s_dict.values()) - s_dict[0]
limit_list.append(upper_limit)
ww_dict = {1: t_dict, 2: s_dict}  # 2桁目

i = 3
max_limit = 10 ** 5
while upper_limit <= max_limit:
    # 3桁目
    w_dict = {
        k: ww_dict[i - 1][k - 1] + ww_dict[i - 1][k] + ww_dict[i - 1][k]
        for k in range(1, 9)
    }
    w_dict[0] = ww_dict[i - 1][0] + ww_dict[i - 1][1]
    w_dict[9] = ww_dict[i - 1][8] + ww_dict[i - 1][9]
    ww_dict[i] = w_dict
    upper_limit = limit_list[-1] + sum(w_dict.values()) - w_dict[0]
    limit_list.append(upper_limit)
    i += 1

# K = 208644

for i, l in enumerate(limit_list):
    if l >= K:
        keta = i + 1
        break

keta_list = list(range(1, keta + 1))

ans_list = []

# i-1桁目のMAX値
t = limit_list[keta - 2]

for i in keta_list[::-1]:
    # i桁目の数字を決めたい
    if i == keta_list[-1]:
        # iが最大桁の場合の候補の数字
        number_list = list(range(1, 10))
    else:
        if ans_list[-1] == 9:
            max_n = 9
        else:
            max_n = ans_list[-1] + 1

        min_n = 0 if ans_list[-1] == 0 else ans_list[-1] - 1

        number_list = list(range(min_n, max_n + 1))
    for n in number_list:
        if i == 1:
            w = t + 1
        else:
            w = t + ww_dict[i][n]
        if w >= K:
            ans_list.append(n)
            break
        # 超えていなかったら更新
        t = w

ans = "".join([str(i) for i in ans_list])
print(ans)

Submission status: Wrong Answer

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:
            print(inParam+str(item))
            myTupp = dfs(inParam+str(item), digits, lunlunCount, lunlun)
            lunlunCount = myTupp[0]
            print(myTupp)
            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: Wrong Answer

Solution code:
import math
import queue

def readInt():
	return int(input())

def readInts():
	return list(map(int, input().split()))

def readChars():
	return input().split()


q = queue.Queue()

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

n = readInt()

for i in range(1,100000):
	a = str(q.get())
	b = int(a[-1])
	print(b)
	if b!=0:
		q.put(int(a+str(b-1)))
	q.put(int(a+str(b)))
	if b==9:
		q.put(int(a+str(b+1)))	
	if i==n:
		print(int(a))
		break

Submission status: Wrong Answer

Solution code:
from collections import deque
a=int(input())
q=deque([1,2,3,4,5,6,7,8,9])
def dfs(k):
  while k<=a:
    s=q.popleft()
    if s-1>=0:
      q.append(s*10+s-1)
      k=k+1
    q.append(s*10+s)
    k=k+1
    if s+1<=9:
      q.append(s*10+s+1)
      k=k+1
  print(q.pop())
 
if a<=9:
  print(a)
else:
  dfs(9)

Submission status: Wrong Answer

Solution code:
import queue
N = int(input())

q =  queue.Queue()
for i in range(1,10):
    q.put(i)

i = 0
while not q.empty():
    out = q.get()
    i += 1
    if i == N:
        break
    b = out*10
    if out % 10 != 0:
        q.put(b+out%10-1)
    q.put(b+out%10)
    q.put(b+out%10+1)
print(out)

Submission status: Wrong Answer

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

'''
100000
99990
90000
'''

K = int(input())
# K = 100000 - K

# c = list(str(3234566667))
# c = [int(i) for i in c][::-1]
c = 1

for i in range(K):
    str_c = list(str(c))
    str_c = [int(i) for i in str_c][::-1]

    keta = len(str_c)
    # print(c)
    # print(str_c)

    if set(str_c) == set([9]):
        c = c + 1
        continue

    for ket in range(keta):
        # 次の桁を見る
        if ket == keta - 1:
            str_c[ket] += 1

            for j in range(ket):
                # print(str_c)
                if str_c[ket - j] == 0:
                    str_c[ket - j - 1] = 0
                else:
                    str_c[ket - j - 1] = str_c[ket - j] - 1

            str_c = [str(i) for i in str_c][::-1]
            c = int(''.join(str_c))
            break

        if str_c[ket] == str_c[ket + 1] + 1:
            continue

        # 大きくできるところがあれば増やす
        if abs(str_c[ket] - str_c[ket + 1]) <= 1:
            if str_c[ket] < 9:
                str_c[ket] += 1
                for j in range(ket):
                    if str_c[ket - j] == 0:
                        str_c[ket - j - 1] = 0
                    else:
                        str_c[ket - j - 1] = str_c[ket - j] - 1
                str_c = [str(i) for i in str_c][::-1]
                c = int(''.join(str_c))
                break


print(c)

Submission status: Wrong Answer

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+ans
    if(p%10!=0):q.append(p-1)
    q.append(p)
    if(p%10!=9):q.append(p+1)

print(ans)

Submission status: Wrong Answer

Solution code:
def solve(K: int):
    q = [i for i in range(1, 10)]

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

    print(x)

K = int(input())  # type: int
solve(K)

Submission status: Wrong Answer

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

    q = queue.Queue()
    for i in range(9):
        q.put(i+1)

    count = 0
    while True:
        count = count+1
        a = q.get()

        if count == K:
            break

        tail = int(str(a)[-1])
        for i in range(10):
            if abs(tail-i) > 1:
                continue
            q.put(int(str(a)+str(i)))

    print(a)

Submission status: Wrong Answer

Solution code:
def solve(K: int):
    q = [i for i in range(1, 10)]

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

    print(x)

K = int(input())  # type: int
solve(K)

Submission status: Wrong Answer

Solution code:
K = int(input())

dig = 10
# dp[i][j] := jで始まるi桁のルンルン数の数
dp = [[0 for _ in range(10)] for _ in range(dig + 1)]

# 1桁
for j in range(0, 10):
    dp[1][j] = 1 # jで始まる1桁のルンルン数の数

# 2〜3桁
for i in range(2, dig + 1): # 2〜3桁
    dp[i][0] = dp[i - 1][0] + dp[i - 1][1]
    for j in range(1, 9):
        # jで始まるi桁のルンルン数の数 = j-1, j, またはj+1で始まるi-1桁のルンルン数の数
        dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] + dp[i - 1][j + 1]
    dp[i][9] = dp[i - 1][8] + dp[i - 1][9]

####################################

ac = 0
for i in range(1, dig + 1):
    for j in range(1, 10):
        ac += dp[i][j]
        if ac >= K:
            ans = j * (10 ** (i - 1))
            break
    else:
        continue
    break

# MSBがjであるi桁の数字
rem = K - ac + dp[i][j]
while i > 1:
    if j == 0: # 次の桁は0か1
        jlist = [0, 1]
    elif j == 9: # 次の桁は8か9
        jlist = [8, 9]
    else:  # 次の桁はj-1かjかj+1
        jlist = [j - 1, j, j + 1]

    for jj in [j - 1, j, j + 1]:
        if dp[i - 1][jj] < rem:
            rem -= dp[i - 1][jj]
        else:
            break
    j = jj
    i -= 1
    ans += j * 10 ** (i - 1)

print(ans)

Submission status: Wrong Answer

Solution code:
# from sys import stdin
import sys
global cnt1


def bts(A, cnt, max):
    # print(A)
    if cnt == max:
        global cnt1
        cnt1 = cnt1+1
        if cnt1 == K:
            print(A)
            sys.exit()
        return
    cnt = cnt+1
    if A % 10 == 0:
        bts(A*10+(A % 10), cnt, max)
        bts(A*10+(A % 10)+1, cnt, max)
    elif A % 10 == 9:
        bts(A*10+(A % 10)-1, cnt, max)
        bts(A*10+(A % 10), cnt, max)
    else:
        bts(A*10+(A % 10)-1, cnt, max)
        bts(A*10+(A % 10), cnt, max)
        bts(A*10+(A % 10)+1, cnt, max)


K = int(input())
# print(K)
N = 9
A = [1, 2, 3, 4, 5, 6, 7, 8, 9]
# global cnt1
cnt1 = 9
for k in range(2, 11):
    for i in range(len(A)):
        bts(A[i], 1, k)
# print(cnt1)

Submission status: Wrong Answer

Solution code:
# from sys import stdin
import sys
global cnt1


def bts(A, cnt, max):
    # print(A)
    if cnt == max:
        global cnt1
        cnt1 = cnt1+1
        if cnt1 == K:
            print(A)
            sys.exit()
        return
    cnt = cnt+1
    if A % 10 == 0:
        bts(A*10+(A % 10), cnt, max)
        bts(A*10+(A % 10)+1, cnt, max)
    elif A % 10 == 9:
        bts(A*10+(A % 10)-1, cnt, max)
        bts(A*10+(A % 10), cnt, max)
    else:
        bts(A*10+(A % 10)-1, cnt, max)
        bts(A*10+(A % 10), cnt, max)
        bts(A*10+(A % 10)+1, cnt, max)


K = int(input())
# print(K)
N = 9
A = [1, 2, 3, 4, 5, 6, 7, 8, 9]
# global cnt1
cnt1 = 9
for i in range(len(A)):
    bts(A[i], 1, 10)
# print(cnt1)

Submission status: Wrong Answer

Solution code:
from collections import deque

k = 9  #+ (9*3-1)
count = 0
q = deque(range(1,10))

while count < k:
    l = q.popleft()
    resid = l % 10
    if resid != 0: q.append(l*10 + resid - 1)

    q.append(l*10 + resid)
    
    if resid != 9: q.append(l*10 + resid + 1)
    
    count += 1

print(l)