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 queue import Queue

K = int(input())

# 1 2 3 4 5 6 7 8 9 10 11 12 21 22 23 32 33 34 ... 98 99 100

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

# print(q.queue)

for i in range(K):
    r = q.get()
    
    if r % 10 != 0:
        q.put(r * 10 + r % 10 - 1)

    q.put(r * 10)

    if r % 10 != 9:
        q.put(r * 10 + r % 10 + 1)
        
print(r)

Submission status: Wrong Answer

Solution code:
K = int(input())
table = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
c = 9
result = []
for i in table:
  runrun = i
  if runrun[-1] == '0':
    table.extend([runrun + str(int(runrun)), 
                   runrun + str(int(runrun)+1)])
    c += 2
  elif runrun[-1] == '9':
    table.extend([runrun + str(int(runrun)-1), 
                   runrun + str(int(runrun))])
    c += 2
  else:
    table.extend([runrun + str(int(runrun)-1), 
                   runrun + str(int(runrun)), 
                   runrun + str(int(runrun)+1)])
    c += 3
  if c>=K:
    print(table[K-1])
    exit()

Submission status: Wrong Answer

Solution code:
k = int(input())

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

c = 0
while k>len(l):
    f = str(l[c])

    if f[-1]!=0:
        l.append(int(f)*10 + int(f[-1])-1)

    l.append(int(f)*10 + int(f[-1]))

    if f[-1]!=9:
        l.append(int(f)*10 + int(f[-1])+1)

    c += 1
print(l[k-1])

Submission status: Wrong Answer

Solution code:
K = int(input())

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

counter = 0
for i in range(1,10**5+1):
    if lunlun(i):
        counter += 1
        if counter == K:
            print(i)
            break
    else:
        continue

Submission status: Wrong Answer

Solution code:
K = int(input())

l = [1,2,3,4,5,6,7,8,9] #１桁のルンルン数
ln = {1,2,3,4,5,6,7,8,9} #既にわかっている分をセット。重複がいやなのでset

def dfs(i):
    n = int(str(i)[-1]) #1桁目を取る
    a,b,c = n-1, n, n+1 #差の絶対値が１未満、+0/+1/-1
    ln.add(i*10+a)
    ln.add(i*10+b)
    if n < 9: #9のときは+1は10になるのでやらない
        ln.add(i*10+c)
    
    if len(str(i)) < 10:
        dfs(i*10+a)
        dfs(i*10+b)
        dfs(i*10+c)

for i in l: #１桁のルンルン数を順番に再帰
    dfs(i)

print(sorted(list(ln))[K-1]) #0-indexを意識してリストのK-1番目を出す

Submission status: Wrong Answer

Solution code:
from collections import deque
K = int(input())
ans = 0
cnt = 9
start = 0
X = deque([[[9],[8],[7],[6],[5],[4],[3],[2],[1]]])
for _ in range(10000):
    X.append(deque([]))
for i in range(1,10000):
    now_cnt = cnt
    for x in list(X[i-1]):
        for j in range(10,0,-1):
            if abs(x[len(x)-1]-j+1) <= 1:
                X[i].append(x+[j-1])
                cnt += 1
    if cnt >= K:
        X[i].reverse()
        lun = X[i][K-now_cnt-1]
        
        N = []
        
        for n in lun:
          N.append(str(n))
        
        print(''.join(N))
        exit()

Submission status: Wrong Answer

Solution code:
x = int(input())

runrun=[[1,2,3,4,5,6,7,8,9],[]]
count=9
keta=2
end=False
ans=-1

if x<=9:
    print(x)
    end=True

while True:
    if end:
        break

    for ini in runrun[keta-2]:

        if ini%10==0:
            runrun[keta-1].append(ini*10)
            count+=1
            if count==x:
                end=True
                ans=ini*10
                break
            runrun[keta-1].append(ini*10+1)
            count+=1
            if count==x:
                end=True
                ans=ini*10+1
                break

        elif ini%10==9:
            runrun[keta-1].append(ini*10+8)
            count+=1
            if count==x:
                end=True
                ans=ini*10+8
                break
            runrun[keta-1].append(ini*10+9)
            count+=1
            if count==x:
                end=True
                ans=ini*10+9
                break

        else:
            runrun[keta-1].append(ini*10+ini%10-1)
            count+=1
            if count==x:
                end=True
                ans=ini*10+ini%10-1
                break
            runrun[keta-1].append(ini*10+ini%10)
            count+=1
            if count==x:
                end=True
                ans=ini*10+ini%10
                break
            runrun[keta-1].append(ini*10+ini%10+1)
            count+=1
            if count==x:
                end=True
                ans=ini*10+ini%10+1
                break

    keta +=1
    runrun.append([])

print(ans)

Submission status: Wrong Answer

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

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

print(x)

Submission status: Wrong Answer

Solution code:
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""

from collections import deque
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def floor(a, b):
    """floor(a/b) 整数値を返す"""
    c = (a - a % b)/b
    return int(c)


def main():

    K = int(input())
    q = deque()
    for i in range(1, 10):
        q.append(i)
    cnt = 9
    if cnt >= K:
        print(q[K-1])
        sys.exit()
    while cnt < K:
        x = q.popleft()
        d = x % 10
        for v in [d-1, d, d+1]:
            if 0 <= v <= 9:
                y = x*10 + v
                q.append(y)
                cnt += 1
    print(y)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

K = int(input())

dq = deque(list(range(1,10)))

rep = 0

while rep < K:
    now = dq.popleft()
    rep += 1
    for i in (-1,0,1):
        if 0 <= now%10+1<10:
            dq.append(now*10+now*10+i)

print(now)

Submission status: Wrong Answer

Solution code:
from collections import deque

K = int(input())

dq = deque(list(range(1,10)))

rep = 0

while rep < K:
    now = dq.popleft()
    rep += 1
    for i in (-1,0,1):
        if 0 <= now%10+1<10:
            dq.append(now*10+i)

print(now)

Submission status: Wrong Answer

Solution code:
k = int(input())

L = [1,2,3,4,5,6,7,8,9]
i = 0
while i < k:
    if int(str(L[i])[-1]) == 1:
        n1 = L[i]*10 
        n2 = L[i]*10 + L[i]%10
        n3 = L[i]*10 + L[i]%10 +1
        L.append(n1)
        L.append(n2)
        L.append(n3)
    elif 2 <= int(str(L[i])[-1]) <= 8:
        n1 = L[i]*10 + L[i]%10 -1
        n2 = L[i]*10 + L[i]%10
        n3 = L[i]*10 + L[i]%10 +1
        L.append(n1)
        L.append(n2)
        L.append(n3)
    elif int(str(L[i])[-1]) == 9:
        n1 = L[i]*10 + L[i]%10 -1
        n2 = L[i]*10 + L[i]%10
        L.append(n1)
        L.append(n2)
    i +=1
print(L[k-1])

Submission status: Wrong Answer

Solution code:
K = int(input())
data = []
C = 0
num = 0
def runrun(a):
	if len(str(a)) == 1:
		return True
	else:
		for i in range(len(str(a))-1):
			difference_digit = int(str(a)[i+1])-int(str(a)[i])
			if difference_digit**2 <= 1:
				return True
while C < K:
	num += 1
	if runrun(num):
		data.append(num)
		C += 1
print(data[-1])

Submission status: Wrong Answer

Solution code:
K = int(input())
data = []
C = 0
num = 0
def runrun(a):
	if len(str(a)) == 1:
		return True
	else:
		for i in range(len(str(a))-1):
			difference_digit = int(str(a)[i+1])-int(str(a)[i])
			if difference_digit**2 <= 1:
				return True
while C < K:
	num += 1
	if runrun(num):
		data.append(num)
		C += 1
print(data)

Submission status: Wrong Answer

Solution code:
def dfs(r):
    global l
    if len(r) == 11:
        return
    l.append(int(r))
    for i in range(-1, 2):
        tmp = int(r[-1]) + i
        if 0 <= tmp <= 9:
            dfs(r + str(tmp))


k = int(input())
l = []
for i in range(1, 10):
    dfs(str(i))
print(sorted(l)[k])

Submission status: Wrong Answer

Solution code:
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=q
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)


K = readInt()

q = queue.Queue()

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

ans = 0
for i in range(K):
	ans = q.get()
	if str(ans)[-1]=="0":
		q.put(int(str(ans)+"0"))
		q.put(int(str(ans)+"1"))
	elif str(ans)[-1]=="9":
		q.put(int(str(ans)+"8"))
		q.put(int(str(ans)+"9"))
	else:
		q.put(int(str(ans)+str(ans-1)))
		q.put(int(str(ans)+str(ans)))
		q.put(int(str(ans)+str(ans+1)))

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=q
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)


K = readInt()

q = queue.Queue()

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

ans = 0
for i in range(K):
	ans = q.get()
	if str(ans)[-1]==0:
		q.put(int(str(ans)+"0"))
		q.put(int(str(ans)+"1"))
	elif str(ans)[-1]==9:
		q.put(int(str(ans)+"8"))
		q.put(int(str(ans)+"9"))
	else:
		q.put(int(str(ans)+str(ans-1)))
		q.put(int(str(ans)+str(ans)))
		q.put(int(str(ans)+str(ans+1)))

print(ans)

Submission status: Wrong Answer

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

d = deque()

for i in range(1,10):
	d.append(i)

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

print(x)

Submission status: Wrong Answer

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

present = [1,2,3,4,5,6,7,8,9]
while K >= len(present):
    K -= len(present)
    next = []
    for i in range(len(present)):
        tmp = present[i]
        r = tmp % 10
        if r != 0:
            next.append(tmp * 10 + tmp -1)
        next.append(tmp * 10 + tmp)
        if r != 9:
            next.append(tmp * 10 + tmp +1)
    present = next

print(present[K-1])

Submission status: Wrong Answer

Solution code:
N=int(input())
from collections import deque
q=deque([1,2,3,4,5,6,7,8,9])
a=0
for _ in range(N):
  a=q.popleft()
  if a%10==0:
    q.append(a*10)
    q.append(a*10+1)
  if a%10==9:
    q.append(a*10+8)
    q.append(a*10+9)
  else:
    q.append(a*10+a%10-1)
    q.append(a*10+a%10)
    q.append(a*10+a%10+1)
print(a)

Submission status: Wrong Answer

Solution code:
K = int(input())
mem = [1,2,3,4,5,6,7,8,9] # 生成後の値を列挙する
cur_keta = 0

while True:
    if len(mem) > K:
        break

    old_mem = []
    old_mem = mem.copy() # 

    for m in old_mem:
        for x in range(-1,2):
            d = int(m%10)+x
            if d < 0 or d > 9:
                continue;
            dx = m*10 + d
            mem.append(dx)

print(mem[K-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(K-1):
    num = q.get()
    if num%10!=0:
        q.put(10*num+(num%10)-1)
    q.put(num*10)
    if num%10!=9:
        q.put(10*num+(num%10)+1)
    
        
print(q.get())

Submission status: Wrong Answer

Solution code:
import queue
import time
import sys
input = sys.stdin.readline


def main():
    K = int(input().strip())
    que = queue.Queue()
    [que.put(i) for i in range(1, 10)]
    for _ in range(K):
        answer = que.get()
        if answer % 10 != 0:
            que.put(10*answer + answer-1)
        que.put(10 * answer + answer)
        if answer % 10 != 9:
            que.put(10*answer + answer + 1)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
k = int(input())

ans = 0

if k<10:
    ans = k
elif k <= 35:
    ans = ((k-7)//3)*10 +((k-7)//3-1) +(k-9+2)%3
else:
    if (k-35)%28 <= 2:
        ans = ((k-35)//28+1)*100 +(k-35)%28 -1
    else:
        ans = ((k-35)//28+1)*100 +(((k-35)%28)//3)*11 +((k-35)%28)%3 -1

print(ans)

Submission status: Wrong Answer

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

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

for i in range(k):
    x = q.get()
    if i == k-1:
        break
    else:
        if not x % 10 == 0:
            q.put(10*x + (x % 10) -1)
            q.put(10*x + (x % 10))
        if not x % 10 == 9:
            q.put(10*x + (x % 10) +1)

print(x)

Submission status: Wrong Answer

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

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

for i in range(k):
    x = q.get()
    if i == k-1:
        break
    else:
        if not x % 10 == 0:
            q.put(10*x + (x % 10) -1)
            q.put(10*x + (x % 10))
            q.put(10*x + (x % 10) +1)

print(x)

Submission status: Wrong Answer

Solution code:
k = int(raw_input())

import collections
q = collections.deque(range(1,10))
res = []
while(len(res) < k):
	u = q.popleft()
	res.append(u)
	for ld in sorted([((u%10)+ delta)%10 for delta in [-1,0,+1]]):
		q.append(u*10 + ld)

print res[k-1]

Submission status: Wrong Answer

Solution code:
K = int(input())
count = 0
import math
def jud(a, b):
    if abs(a-b) <= 1:
        return True
    else:
        return False
    
for i in range(1, 10**5+1):
    is_flag = True
    keta = int(math.log10(i))
    if keta == 0:
        is_flag = True
    elif keta >=1:
        for j in range(0, keta):
            if is_flag == False:
                break
            else:
                a = i%(10**(j+1))//(10**j)
                b = i%(10**(j+2))//(10**(j+1))
                is_flag = jud(a, b)
    if is_flag == True:
        count += 1
        if count < K:
            continue
        elif count == K:
            print(i)
            break

Submission status: Wrong Answer

Solution code:
a=int(input())
l=[[0]*10 for _ in range(10)]
l[0]=[1]*10
for i in range(1,10):
    for j in range(10):
        if j!=9 and j!=0:
            l[i][j]=l[i-1][j-1]+l[i-1][j]+l[i-1][j+1]
        elif j==0:
            l[i][j]=l[i-1][j]+l[i-1][j+1]
        else:
            l[i][j]=l[i-1][j-1]+l[i-1][j]
count=0
i=0
while count<a:
    count+=sum(l[i])-l[i][0]
    i+=1
i-=1
count-=sum(l[i])-l[i][0]
j=1
while count<a:
    count+=l[i][j]
    j+=1
j-=1
count-=l[i][j]
k=a-count
ll=[j]
jj=j-1
for ii in range(i):
    while k>0:
        k-=l[i-ii-1][jj]
        jj+=1
    jj-=1
    k+=l[i-ii-1][jj]
    ll.append(jj)
    jj-=1
for jjj in ll:
    print(jjj,end='')

Submission status: Wrong Answer

Solution code:
import queue

k = int(input())

q = queue.Queue()

for i in range(1,10):
    q.put(i)
    
c = 1
while c<k:
    x = q.get()
    r = x%10
    if r != 0 and r != 9:
        q.put(10*x+r-1)
        q.put(10*x+r)
        q.put(10*x+r+1)
        c = c+1
    if r == 0:
        q.put(10*x)
        q.put(10*x+1)
        c = c+1
    if r == 9:
        q.put(10*x+r-1)
        q.put(10*x+r)
    if c == k:
        print(x)

Submission status: Wrong Answer

Solution code:
k=int(input())
a=[]
for i in range(1,10):
    a.append(i)
for i in range(k):
    x=a[i]
    if x%10!=0:
        a.append(x*10+x%10-1)
    a.append(x*10+x%10)
    if x%10!=9:
        a.append(x*10+x%10+1)
mod=10**9+7
print(x%mod)

Submission status: Wrong Answer

Solution code:
ONE_KETA = 10

K = int(input())

# 入力値が一桁
if(K < ONE_KETA):
	print(K)
	exit

# それ以外
# キューを作る
queue_list = [i for i in range(1, ONE_KETA)]
K -= len(queue_list)

# 2桁目以降
while(K > 0):
	# キューを取り出す
	val = queue_list.pop(0)

	# 一桁の値を取り出す
	tmp_s_num = val % ONE_KETA

	for i in range(-1, 2):
		# 末尾9、+1の時は飛ばす
		if(tmp_s_num == 9 and i == 1):
			continue
		elif(tmp_s_num == 0 and i == -1):
			continue
		else:
			# 10倍 + 元の値 + (-1,0,+1)
			tmp_val = val * 10 + tmp_s_num + i
			queue_list.append(tmp_val)
			K -= 1

# 最後の値が答え
print(queue_list.pop())

Submission status: Wrong Answer

Solution code:
K=int(input())
List=[1,2,3,4,5,6,7,8,9]
N=0
M=9
while len(List)<K:
    for i in range(N,M):
        last_number=int(str(List[i])[-1])
        times10=10*List[i]
        if last_number!=0 or last_number!=9:
            List.append(times10+last_number-1)
            List.append(times10+last_number)
            List.append(times10+last_number+1)
        elif last_number==0:
            List.append(times10)
            List.append(times10+1)
        else:
            List.append(times10+8)
            List.append(times10+9)
        N=M
        M=len(List)
print(List[K-1])

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

K = int(read())

pre_lis = []
for i in range(1,10):
    pre_lis.append(str(i))
print(pre_lis)
ct = 9
if K <= 9:
    print(pre_lis[K-1])
else:
    new_lis = []
    flag = False
    while ct < K:
        for num in pre_lis:
            pre_num = int(num[-1])
            for i in range(10):
                if abs(pre_num-i) <= 1:
                    new_lis.append(num + str(i))
                    ct+=1
                    #print((new_lis[-1]))
                    if ct == K:
                        print(new_lis[-1])
                        flag = True
                        break
            pre_lis = new_lis
            if flag:
                break
        if flag:
            break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k=int(input())

Lunlun=[1,2,3,4,5,6,7,8,9]
for i in range(0,k-1):
    #print(Lunlun,"Lunlun")
    x=Lunlun[0]
    if x%10 != 0 :                  #x mod 10 ̸= 0 なら、 10x + (x mod 10) − 1 を Enqueue
        Lunlun.append(10*x + x%10 - 1)
        Lunlun.append(10*x + x%10)       #10x + (x mod 10) を Enqueue
        if x%10 != 9 :              #さらに x mod 10 ̸= 9 なら、 10x + (x mod 10) + 1を Enqueu
            Lunlun.append(10*x + x%10 + 1)
    del(Lunlun[0])
    
#print(Lunlun)
print(Lunlun[0])

Submission status: Wrong Answer

Solution code:
K = int(input())

if K < 10:
	print(K)
    
n = list(range(1, 10))	

for i in n:
	for j in range(max(i%10-1, 0), min(i%10+2, 10)):
		n.append(10*i + j)
	if len(n) > K:
		print(n[K-1])
		break

Submission status: Wrong Answer

Solution code:
from collections import deque
K = int(input())
d = deque(range(1, 10))
for i in range(K):
    x = d.popleft()
    if x % 10 != 0:
        d.append(10*x-1)
    d.append(10*x)
    if x % 10 != 9:
        d.append(10*x+1)
print(x)

Submission status: Wrong Answer

Solution code:
# import numpy as np


def solve():
    print(ll_no_dup[k-1])
    return






#a = [int(i) for i in input().split(" ")]




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

it = 0
count = 0
all_count = len(lunluns)
while count <= 2*10 ** 5:
    it = len(lunluns)
    last_count = all_count
    all_count = 0
    for i in range(it-last_count, it):
        last_val = int(lunluns[i][-1])
        if last_val > 0:
            lunluns.append(lunluns[i] + str(last_val - 1))
            count += 1
            all_count +=1
        lunluns.append(lunluns[i] + str(last_val))
        count += 1
        all_count +=1
        if last_val < 9:
            lunluns.append(lunluns[i] + str(last_val + 1))
            count += 1
            all_count +=1
        if count > 2*10 ** 5:
            break

ll_no_dup = [str(0)]
for i in range(1, len(lunluns)):
    if lunluns[i]!=lunluns[i-1]:
        ll_no_dup.append(lunluns[i])


k = int(input())
solve()

Submission status: Wrong Answer

Solution code:
# import numpy as np


def solve():
    print(ll_no_dup[k-1])
    return






#a = [int(i) for i in input().split(" ")]




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

it = 0
count = 0
all_count = len(lunluns)
while count <= 10 ** 5:
    it = len(lunluns)
    last_count = all_count
    all_count = 0
    for i in range(it-last_count, it):
        last_val = int(lunluns[i][-1])
        if last_val > 0:
            lunluns.append(lunluns[i] + str(last_val - 1))
            count += 1
            all_count +=1
        lunluns.append(lunluns[i] + str(last_val))
        count += 1
        all_count +=1
        if last_val < 9:
            lunluns.append(lunluns[i] + str(last_val + 1))
            count += 1
            all_count +=1
        if count > 10 ** 5:
            break

ll_no_dup = [str(0)]
for i in range(1, len(lunluns)):
    if lunluns[i]!=lunluns[i-1]:
        ll_no_dup.append(lunluns[i])

k = int(input())
solve()

Submission status: Wrong Answer

Solution code:
n=int(input())
if n<=10 : 
  print(n)
  exit()
  
ans=[0 for i in range(10**5+21)]
Q=[0,1,2,3]
def li(x):
  if x==0 : return [0,1]
  if x==9 : return [8,9]
  return [x-1,x,x+1]

now=0
for q in Q:
  W=[i for i in range(10)] if q==0 else li(q)
  for w in W:
    E=[i for i in range(10)] if [q,w]==[0,0] else li(w)
    for e in E:
      R=[i for i in range(10)] if [q,w,e]==[0,0,0] else li(e)
      for r in R:
        T=[i for i in range(10)] if [q,w,r,e]==[0,0,0,0] else li(r)
        for t in T:
          Y=[i for i in range(10)] if [q,w,e,r,t]==[0,0,0,0,0] else li(t)
          for y in Y:
            U=[i for i in range(10)] if [q,w,e,r,t,y]==[0,0,0,0,0,0] else li(y)
            for u in U:
              I=[i for i in range(10)] if [q,w,e,r,t,y,u]==[0,0,0,0,0,0,0] else li(u)
              for i in I:
                O=[i for i in range(10)] if [q,w,e,r,t,y,u,i]==[0,0,0,0,0,0,0,0] else li(i)
                for o in O:
                  P=[i for i in range(10)] if [q,w,e,r,t,y,u,i,o]==[0,0,0,0,0,0,0,0,0,0] else li(o)
                  for p in P:
                    
                    ans[now]= 10**9*q + 10**8*w + 10**7*e + 10**6*r + 10**5*t + 10**4*y + 1000*u + 100*i + 10*o + p
                    
                    if now>=10**5+2 : break
                    now+=1

ans=list(set(ans))
ans.sort()
print(ans[n])

Submission status: Wrong Answer

Solution code:
import collections
k = int(input())
li = [str(i) for i in range(1,10)]
st_li = li[:]

q = collections.deque(li)
count = 0
n = 10 ** 10

for i in range(1,n):
    # print(st_li)
    a = q.popleft()
    num = int(a[-1])
    # print(num)
    if num != 0:
        aa = a + str(num-1)
        st_li.append(aa)
        q.append(aa)
        count += 1
    aa = a + str(num)
    st_li.append(aa)
    count += 1
    if num != 9:
        aa = a + str(num+1)
        st_li.append(aa)
        q.append(aa)
        count += 1
    if count > k:
        print(st_li[k-1])
        exit(0)

Submission status: Wrong Answer

Solution code:
def func(num):
    str_num=str(num)

    keta=len(str_num)

    if keta==1:
        return 1

    ans=1
    for j in range(2,keta+1):
        y=int(str_num[j-1])-int(str_num[j-2])
        if y==-1 or y==0 or y==1:
            ans=1
        else:
            ans=0
    return ans

input = int(input())

count=0
for i in range(1,1000000000):
    x=func(i)
    if x==1:
        count+=1
    if input==count:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
k = int(input())

def fun(k):
    lun_luns = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    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])
        elif mod == 0:
            lun_luns.extend([n + mod, n+1])
        else:
            lun_luns.extend([n+mod-1, n, n+mod+1])
        index += 1
    
    return lun_luns[k-1]

print(fun(k))

Submission status: Wrong Answer

Solution code:
k = int(input())

def fun(k):
    lun_luns = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    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])
        elif mod == 0:
            lun_luns.extend([n, n+1])
        else:
            lun_luns.extend([n+mod-1, n, n+mod+1])
        index += 1
    
    return lun_luns[k-1]

print(fun(k))

Submission status: Wrong Answer

Solution code:
K=int(input())
B=[]
j=0
x=0
inLoop=True
while inLoop:
    x+=1
    z=str(x)
    n=len(z)
    if n>4:
        x1=x%1000
        if x1 in B:
                for i in range(n-1):
                    y=int(z[i])-int(z[i+1])
                    if abs(y)<=1:
                        j+=1
                if j==(n-1):
                    B.append(x)
                    j=0
                else:
                    j=0
                if len(B)==K+1:
                    break
    else:       
        for i in range(n-1):
            y=int(z[i])-int(z[i+1])
            if abs(y)<=1:
                j+=1
        if j==(n-1):
            B.append(x)
            j=0
        else:
            j=0
        if len(B)==K+1:
            break
print(B[K-1])

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import collections

k = int(input())
li = [str(i) for i in range(1,10)]
str_li = li[:]
q = collections.deque(li)
count = 0
n = 10**10

for i in range(1,n):
    a = q.popleft()
    num = int(a[-1])
    if num != 0:
        aa = a + str(num-1)
        str_li.append(aa)
        count+=1
    aa = a + str(num)
    str_li.append(aa)
    q.append(aa)
    count+=1
    if num != 9:
        aa = a + str(num+1)
        str_li.append(aa)
        q.append(aa)
        count+=1
    if count > k:
        print(str_li[k-1])
        break

Submission status: Wrong Answer

Solution code:
K = int(input())
# 1桁
K1 = [x for x in range(1, 10)]
#2桁

def add_2(Kn):
    K_ = []
    for i in Kn:
        
        K_.append(10*i + (i % 10 - 1))
        K_.append(10*i + i % 10)
        if i % 10 < 9:
            K_.append(10*i + (i % 10+ 1))

    return K_

def add_(Kn):
    K_ = []
    for i in Kn:
        if i%10 > 0:
            K_.append(10*i + (i % 10 - 1))
        K_.append(10*i + i % 10)
        if i % 10 < 9:
            K_.append(10*i + (i % 10+ 1))

    return K_

out = [K1, add_2(K1)]
for k in range(1, 9):
    print(k)
    out.append(add_(out[k]))

out = sum(out, [])
print(out[K-1])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
K = int(input())

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

for i in range(100):
  if lunlun(i):
    print(i,end =" ")

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

print(j-1)

Submission status: Wrong Answer

Solution code:
from collections import deque
k=int(input())

q=deque(list(range(1, 10)))
cnt=0
ans=[]
 
for i in range(k):
    a = q.popleft()
    ans.append(a)
    b = a * 10 +  a % 10 
    if a % 10 != 0:
        q.append(b - 1)
    q.append(b)
    if a % 10 != 9:
        q.append(b + 1)
print(ans)
print(ans[k-1])