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:
K = int(input())

count = 9
lunlun = [[0,1,2,3,4,5,6,7,8,9]]
ans = [1,2,3,4,5,6,7,8,9]

keta = 2

while count < K:
    lunlun.append([])
    for a in lunlun[keta - 2]:
        t = int(str(a)[0])
        if t - 1 > 0:
            lunlun[keta - 1].append(int(str(t-1)+str(a)))
            count += 1
        if not t == 0:
            lunlun[keta - 1].append(int(str(t)+str(a)))
            count += 1
        if t + 1 <= 9:
            lunlun[keta - 1].append(int(str(t+1)+str(a)))
            count += 1
    lunlun[keta - 1].sort()
    for b in lunlun[keta - 1]:
        ans.append(b)
    keta += 1
print(ans[K-1])

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
k = int(input())

lun = []
for i in range(1,10):
    lun.append(i)

if k <= 9:
    print(lun[k-1])
    exit()

prev_lun = deepcopy(lun)

while True:
    size = len(lun)
    for pl in prev_lun:
        for i in [-1, 0, 1]:
            d = pl%10 + i
            if 0 <= d <= 9:
                lun.append(pl*10 + d)
            if len(lun) == k:
                print(lun[k-1])
                exit()
                
    prev_lun = deepcopy(lun[size+1:])

Submission status: Wrong Answer

Solution code:
k=int(input())
s=9
l=[1,2,3,4,5,6,7,8,9]
n=0
while s<10**5+1:
  t=l[n]
  z=int(str(t)[-1])
  l.append(t*10+z-1)
  l.append(t*10+z)
  s+=2
  if z<9:
    l.append(t*10+z+1)
    s+=1
  n+=1
l.sort()
print(l[k-1])

Submission status: Wrong Answer

Solution code:
import queue
k = int(input())
q = [1,2,3,4,5,6,7,8,9]
qq = queue.Queue()
for i in range(1,10):
	qq.put(i)

for i in range(k):
	x = qq.get()
	if x%10 != 0:
		qq.put(10*x + (x%10) -1)
	qq.put(10*x + (x%10))
	if x%9 != 0:
		qq.put(10*x + (x%10) +1)
		
print(x)

Submission status: Wrong Answer

Solution code:
k = int(input())
q = [1,2,3,4,5,6,7,8,9]

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

Submission status: Wrong Answer

Solution code:
k = int(input())
q = [1,2,3,4,5,6,7,8,9]

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

Submission status: Wrong Answer

Solution code:
from collections import deque

n = int(input())

c = 0
q = deque()
for i in range(1, 10):
    q.append(i)

k = 1
while c < n:
    k = q.popleft()
    if k%10:
        q.append(10*k + k%10 - 1)
        q.append(10 * k + k % 10)
        if k%10 != 9:
            q.append(10*k + (k%10) + 1)
    c += 1

print(k)

# c = 0
# a = 1
# i = 1
#
# while c < n:
#     s = str(i)
#     f = 0
#     j=0
#     while j < len(s) -1:
#         if abs(int(s[j]) - int(s[j+1])) > 1:
#             f = 1
#             break
#         j = j + 1
#     if f == 0:
#         # print(i)
#         c = c + 1
#         a = i
#     if c == n:
#         break
#     i += 1
#
# print(a)

Submission status: Wrong Answer

Solution code:

n=int(input())
from collections import deque
k=deque([])
z=9
m=0
if n<10:
    print(n)
    exit()
for i in range(1,10):
    k.append(i)
while z!=n:
    m=k.pop()
    k.popleft
    if m%10!=0:
        ans=10*m+(m%10)-1
        k.append(ans)
        z+=1
        if z==n:
            print(ans)
            exit()
    ans=10*m+(m%10)    
    k.append(ans)
    z+=1
    if z==n:
        print(ans)
        exit()
    if m%10!=9:
        ans=10*m+(m%10)+1
        k.append(ans)
        z+=1
        if z==n:
            print(ans)
            exit()

Submission status: Wrong Answer

Solution code:
n=int(input())
from collections import deque
k=deque([])
z=0
m=0
for i in range(1,10):
    k.append(i)
while z<n:
    m=k.pop()
    k.popleft
    if m%10!=0:
        k.append(10*m+(m%10)-1)
    k.append(10*m+(m%10))
    if m%10!=9:
        k.append(10*m+(m%10)+1)
    z+=1
print(m)

Submission status: Wrong Answer

Solution code:
import queue

k = int(input())
q = queue.Queue()
for i in range(1,9):
  q.put(i)

n = 0
while True:
  val = q.get()
  if val % 10 != 0:
    q.put(10 * val + (val % 10) - 1)
  q.put(10 * val + (val % 10))
  if val % 10 != 9:
    q.put(10 * val + (val % 10) + 1)
  
  n += 1
  if n == k:
    print(val)
    break

Submission status: Wrong Answer

Solution code:
def lunlun(n):
	nums = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
	while len(nums) < n:
		old_nums = list(nums)
		for num in old_nums:
			num = str(num)
			if num[-1] == '0':
				adds = num + '0'
				if int(adds) not in nums:
					nums.add(int(adds))
				adds = num + '1'
				if int(adds) not in nums:
					nums.add(int(adds))
			elif num[-1] == '9':
				adds = num + '9'
				if int(adds) not in nums:
					nums.add(int(adds))
				adds = num + '8'
				if int(adds) not in nums:
					nums.add(int(adds))
			else:
				adds = num + str(int(num[-1]) - 1)
				if int(adds) not in nums:
					nums.add(int(adds))
				adds = num + str(int(num[-1]))
				if int(adds) not in nums:
					nums.add(int(adds))
				adds = num + str(int(num[-1]) + 1)
				if int(adds) not in nums:
					nums.add(int(adds))
			# if num[0] == '1':
			# 	adds = '1' + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))
			# 	adds = '2' + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))
			# elif num[0] == '9':
			# 	adds = '8' + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))
			# 	adds = '9' + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))
			# else:
			# 	adds = str(int(num[0]) - 1) + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))
			# 	adds = str(int(num[0])) + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))
			# 	adds = str(int(num[0]) + 1) + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))

	nums = list(nums)
	# nums = sorted(nums)
	return nums[n - 1]

n = int(input())
print(lunlun(n))

Submission status: Wrong Answer

Solution code:
from collections import deque
def main(k):
    q = deque([])
    for i in range(1, 10):
        q.append(i)
    
    count = 0
    top = -1
    
    while True:
        top = q.popleft()

        count += 1
        if count == k:
            return top

        if top%10 != 0:
            q.append(top*10 + top%10-1)
        q.append(top*10 + top%10)
        if top%10 != 9:
            q.append(top*10 + top%10 + 1)

    return top
k = int(input())
main(k)

Submission status: Wrong Answer

Solution code:
from collections import deque
def main(k):
    q = deque([])
    for i in range(10):
        q.append(i)
    
    count = 0
    top = -1
    while True:
        top = q.popleft()

        count += 1
        if count == k:
            return top

        if top%10 != 0:
            q.append(top*10 + top%10-1)
        q.append(top*10 + top%10)
        if top%10 != 9:
            q.append(top*10 + top%10 + 1)

    return top

k = int(input())
main(k)

Submission status: Wrong Answer

Solution code:
K = int(input())

queue = list(range(1, 10))

if K < 10:
    print(K)
else:
    i = 0
    while K > len(queue):
        if queue[i] % 10 != 0:
            l = 10 * queue[i] + queue[i] % 10 - 1
            queue.append(l)
        
        l = 10 * queue[i] + queue[i] % 10
        queue.append(l)
        
        if queue[i] % 10 != 9:
            l = 10 * queue[i] + queue[i] % 10 + 1
            queue.append(l)
        
        i += 1

    print(queue[-1])

Submission status: Wrong Answer

Solution code:
K = int(input())

queue = list(range(1, 10))

if K <= 10:
    print(K)
else:
    i = 0
    while K > len(queue):
        if queue[i] % 10 != 0:
            l = 10 * queue[i] + queue[i] % 10 - 1
            queue.append(l)
        
        l = 10 * queue[i] + queue[i] % 10
        queue.append(l)
        
        if queue[i] % 10 != 9:
            l = 10 * queue[i] + queue[i] % 10 + 1
            queue.append(l)
        
        i += 1

    print(queue[-1])

Submission status: Wrong Answer

Solution code:
from collections import deque

k = int(input())
q = deque([1,2,3,4,5,6,7,8,9])

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

print(q.pop())

Submission status: Wrong Answer

Solution code:
from collections import deque
def main():
    K = int(input())
    cnt = 0
    mod = 10
    
    q = deque([])
    for i in range(1, 10):
        q.append(i)
    
    while cnt < K:
        x = q.popleft()
        cnt += 1
        if x%mod == 0:
            q.append(10*x + (x%mod))
            q.append(10*x + (x%mod)+1)
        elif x%mod == 9:
            q.append(10*x + (x%mod))
            q.append(10*x + (x%mod) -1)
        else:
            q.append(10*x + (x%mod)-1)
            q.append(10*x + (x%mod))
            q.append(10*x + (x%mod+1))
    print(x)
main()

Submission status: Wrong Answer

Solution code:
k=int(input())
ok=3234566667
ng=0
while ok-ng>1:
  mid=(ok+ng)//2
  s=str(mid)
  dp=[[[0]*3 for _ in range(10)] for _ in range(len(s))]
  for i in range(1,int(s[0])):
    dp[0][i][2]+=1
  dp[0][int(s[0])][1]+=1
  dp[0][0][0]+=1
  for i in range(1,len(s)):
    dp[i][0][0]+=dp[i-1][0][0]
    for j in range(10):
      dp[i][j][2]+=dp[i-1][j][2]
      if j>=1:
        dp[i][j-1][2]+=dp[i-1][j][2]
        if int(s[i])==j-1 and int(s[i-1])==j:
          dp[i][j-1][1]+=dp[i-1][j][1]
        if int(s[i])>j-1:
          dp[i][j-1][2]+=dp[i-1][j][1]
      if j<=8:
        if j!=0:
          dp[i][j+1][2]+=dp[i-1][j][2]
          if int(s[i])==j+1 and int(s[i-1])==j:
            dp[i][j+1][1]+=dp[i-1][j][1]
          if int(s[i])>j+1:
            dp[i][j+1][2]+=dp[i-1][j][1]
        else:
          for l in range(1,10):
            dp[i][l][2]+=dp[i-1][j][0]
      if int(s[i])==j and int(s[i-1])==j:
        dp[i][j][1]+=dp[i-1][j][1]
      if int(s[i])>j:
        dp[i][j][2]+=dp[i-1][j][1]
  cnt=0
  for i in range(10):
    cnt+=sum(dp[len(s)-1][i])
  if cnt-1>=k:
    ok=mid
  else:
    ng=mid
print(ok)

Submission status: Wrong Answer

Solution code:
k=int(input())
mod=3234566667
ans=0
for i in range(1,mod+1):
      flag=True
      for j in range(len(str(i))-1):
            if abs(int(str(i)[-j])-int(str(i)[-(j+1)]))>1:
                  flag=False
      if flag:
            ans+=1
            if ans==k:
                  print(i)
                  exit()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

def check(a):
    for l in range(len(a) - 1):
        if not -1 <= a[l] - a[l + 1] <= 1:
            return False
    return True

x = [0]
k = I()
ret = 0
j = len(x) - 1
while True:
    if x == [9] * len(x):
        x = [1] + [0] * len(x)
        ret += 1
        j = len(x) - 1
        if ret == k:
            print(''.join([str(m) for m in x]))
            exit()
    if j and (x[j - 1] + 1 == x[j] or x[j] == 9):
        j -= 1
        continue
    x[j] += 1
    for n in range(j + 1, len(x)):
        x[j + 1] = x[j] - 1 if x[j] else 0
    j = len(x) - 1
    ret += 1
    if ret == k:
        print(''.join([str(m) for m in x]))
        exit()

Submission status: Wrong Answer

Solution code:
import queue

S = int(input())

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

cnt = 9
num = 9
digit = 0

if S <= 9:
    print(S)
else:
    while cnt <= S:
        num = q.get()
        digit = int(str(num)[-1])
        num = num * 10

        if digit == 0:
            cnt += 1
            for i in range(2):
                if cnt == S:
                    print(num + i)
                    exit()
                else:
                    q.put(num + i)

        elif digit == 9:
            num += digit - 1
            for i in range(2):
                cnt += 1
                if cnt == S:
                    print(num + i)
                    exit()
                else:
                    q.put(num+i)
        else:
            num += digit - 1
            for i in range(3):
                cnt += 1
                if cnt == S:
                    print(num + i)
                    exit()
                else:
                    q.put(num+i)

Submission status: Wrong Answer

Solution code:
import queue

S = int(input())

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

cnt = 9
num = 9
digit = 0

if S <= 9:
    print(S)
else:
    while cnt <= S:
        num = q.get()
        digit = int(str(num)[-1])
        num = num * 10

        if digit == 0:
            cnt += 1
            for i in range(2):
                if cnt == S:
                    print(num + i)
                else:
                    q.put(num+i)

        elif digit == 9:
            num += digit - 1
            for i in range(2):
                cnt += 1
                if cnt == S:
                    print(num + i)
                else:
                    q.put(num+i)
        else:
            num += digit - 1
            for i in range(3):
                cnt += 1
                if cnt == S:
                    print(num + i)
                else:
                    q.put(num+i)

Submission status: Wrong Answer

Solution code:
k = int(input())
num = 0
for _ in range(k):
  num += 1
  digit = [int(digit) for digit in str(num)]
  len_digit = len(digit)
  flag = False
  for i in range(1, len_digit):
    # current_digit = digit[-i]
    # upper_digit = digit[-i-1]
    if digit[-i] > 9:
      digit[-i-1] += 1
      digit[-i] = -1
      flag = True
    elif digit[-i] > digit[-i-1] + 1:
      digit[-i-1] += 1
      digit[-i] = -1
      flag = True
    elif digit[-i] < digit[-i-1] - 1:
      digit[-i] = digit[-i-1] - 1
  if digit[0] > 9:
    num = 10 ** len_digit
  else:
    if flag:
      for i in range(1, len_digit):
        if digit[i] == -1:
          for j in range(i, len_digit):
            digit[j] = max(digit[j-1] - 1, 0)
          break
    num = 0
    for d in digit:
      num = num * 10 + d
print(num)

Submission status: Wrong Answer

Solution code:
import queue

k = int(input())
q = queue.Queue()
for l in range(10)[1:]:
    q.put(l)
if k < 10:
    print(q.queue[k])
k -= 9
for l in range(k):
    dequeued = q.get()
    mod = dequeued % 10
    if mod != 0:
        q.put(dequeued * 10 + mod - 1)
    q.put(dequeued * 10 + mod)
    if mod != 9:
        q.put(dequeued * 10 + mod + 1)
print(q.queue[8])

Submission status: Wrong Answer

Solution code:

K = int(input())
n = 0
cnt = 0
tmp = 0
while cnt < K:
    n = n + 1
    print(n)
    nDigit = []
    nDiv   = []
    flg = True
    digits = len(str(n))
    tmpN = n
    for i in range(0,digits) :
        nDigit.append(tmpN // (10 ** (digits-i-1)))
        tmpN = tmpN % (10 ** (digits-i-1))
    if len(nDigit) == 1 :
        cnt = cnt + 1
        tmp = n
    else :
        tR = 0
        for i in range(0,len(nDigit)-1) :
            if abs(nDigit[i] - nDigit[i+1]) > 1 :
                flg = False
                tR = i
                i = len(nDigit)
        if flg == True :
            cnt = cnt + 1
            tmp = n
        elif nDigit[tR] - nDigit[tR+1] < 0 :
            n = n - (n % (10 ** (digits - tR))) + (nDigit[tR] + 1) * (10 ** (digits-tR-1)) - 1
        elif nDigit[tR] - nDigit[tR+1] > 0 :
            n = n - (n % (10 ** (digits - tR-1))) + (nDigit[tR] - 1) * (10 ** (digits-tR-2)) - 1

#for i in range(0,len(LunList)) :
#    print(i,LunList[i])
print(n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

K = int(input())
n = 1
LunList = [0]
cnt = 0
tmp = 0
while cnt < K:
    LunList.append(0)
    nDigit = []
    nDiv   = []
    flg = True
    tmpN = n
    while tmpN > 0 :
        digits = len(str(tmpN))
        nDigit.append(tmpN // (10 ** (digits-1)))
        nDiv.append(tmpN)
        tmpN = tmpN % (10 ** (digits-1))
    if len(nDigit) == 1 :
        cnt = cnt + 1
        LunList[n] = LunList[tmp] + 1
        tmp = n
    else :
        for i in range(0,len(nDigit)-1) :
            if abs(nDigit[i] - nDigit[i+1]) > 1 :
                flg = False
        if flg :
            cnt = cnt + 1
            LunList[n] = LunList[tmp] + 1
            tmp = n
    n = n + 1
print(n)

Submission status: Wrong Answer

Solution code:
# ABC161D
def f(k):
    if 1 <= k <= 9:
        return k
    nxt = [[0,1], [0,1,2], [1,2,3], [2,3,4], [3,4,5], [4,5,6], [5,6,7], [6,7,8], [7,8,9], [8,9]]
    cum_npi = [0, 9, 35, 110, 327, 956, 2782, 8089, 23527, 68468, 199368]
    for length, begin in enumerate(cum_npi):
        if k < begin:
            found = cum_npi[length - 1]
            break
    begin = 10 ** (length - 1)
    length, begin, found
    k -= found
    x = [[]] * (length + 1)
    x[1] = list(range(1, 10))
    x

    terminate = False
    i = 1
    while True:
        #print(f"a) i = {i}  x = {x}")
        if len(x[i]): # len(x[i])
            digit = x[i][0]
            if i < length: # i, length
                i += 1
                x[i] = nxt[digit].copy()
                #print(f"x) digit = {digit}  nxt[digit] = {nxt[digit]}  i = {i}  x[i] = {x[i]}")
                #print(f"b) i = {i}  x = {x}")
                if i == length: # i, length
                    while len(x[i]): # i, x[i]
                        k -= 1
                        #print(f"c) i = {i}  x = {x}, k = {k}")
                        if k == 0:
                            x.pop(0)
                            #print("answer =", x)
                            ans = "".join([str(j.pop(0)) for j in x])
                            print(ans)
                            terminate = True
                            break
                        else:
                            x[i].pop(0)
                        #print(f"d) i = {i}  x = {x}")
                    else:
                        #print(f"e) i = {i}  x = {x}")
                        while len(x[i]) == 0:
                            i -= 1
                            x[i].pop(0)
                    if terminate:
                        break

f(int(input()))

Submission status: Wrong Answer

Solution code:
K = int(input())
queue = []
for i in range(1, 10):
  queue.append(i)

while K != 0:
  num = queue.pop(0)

  if K <= len(queue):
    print(queue[K-1])
    exit(0)
  K -= 1

  if K == 0:
    print(num)
    exit(0)

  o = int(str(num)[-1])
  for n in [o-1, o, o+1]:
    if n == -1 or n == 10: continue
    queue.append( int(str(num)+str(n)) )

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 += 2
        for j in range(10-c):
          heapq.heappush(a,i+10**c*(10**(j+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())
#a = set(a)
#a = list(a)
for i in range(k):
  heapq.heappop(a)
print(heapq.heappop(a))

Submission status: Wrong Answer

Solution code:

k=int(input())
if(k==0):
    print(0)
#n=int(n)
def luncheck(n):
    f=0
    #n=str(n)
    for i in range(len(n)):
        
        if(int(n[i])-int(n[i-1])<=1):
            f=1
            
        else:
            f=0
            break
    
    return f
#print(luncheck(k))    
count=0
for i in range(1,10**15):
    t=0
    t=t+i
    t=str(t)
    if(luncheck(t)==1):
        count=count+1
    if(count==k):
        print(t)
        #print(i)
        break

#print("count is",count)
    
#print(d1)

Submission status: Wrong Answer

Solution code:

k=int(input())
#n=int(n)
def luncheck(n):
    f=0
    #n=str(n)
    for i in range(len(n)):
        
        if(int(n[i])-int(n[i-1])<=1):
            f=1
            
        else:
            f=0
            break
    
    return f
#print(luncheck(k))    
count=0
for i in range(1,10**15):
    t=0
    t=t+i
    t=str(t)
    if(luncheck(t)==1):
        count=count+1
    if(count==k):
        print(t)
        #print(i)
        break

#print("count is",count)
    
#print(d1)

Submission status: Wrong Answer

Solution code:
import heapq
import sys

def solve(k):
    if k < 10:
        return k
    
    heap = [1,2,3,4,5,6,7,8,9]
    heapq.heapify(heap)

    for i in range(k-1):
        lunlun = heapq.heappop(heap)
        lastDigit = lunlun  % 10
        # print lunlun
        heapq.heappush(heap, (lunlun*10) + lastDigit)

        if lastDigit == 0:
            newlunlun = (lunlun * 10) + 1
            heapq.heappush(heap, newlunlun)    
        elif lastDigit == 9:
            newlunlun = (lunlun * 10) + 8
            heapq.heappush(heap, newlunlun)  
        else:
            newlunlun1 = (lunlun * 10) + lastDigit + 1
            newlunlun2 = (lunlun * 10) + lastDigit - 1
            heapq.heappush(heap, newlunlun1)
            heapq.heappush(heap, newlunlun2)

    return heapq.heappop(heap)

# k = input()
k = 100000
print(solve(int(k)))

Submission status: Wrong Answer

Solution code:
import heapq
import sys

def solve(k):
    if k < 10:
        return k
    
    heap = [1,2,3,4,5,6,7,8,9]
    heapq.heapify(heap)

    for i in range(k-1):
        lunlun = heapq.heappop(heap)
        lastDigit = lunlun  % 10
        # print lunlun
        heapq.heappush(heap, (lunlun*10) + lastDigit)

        if lastDigit == 0:
            newlunlun = (lunlun * 10) + 1
            heapq.heappush(heap, newlunlun)    
        elif lastDigit == 9:
            newlunlun = (lunlun * 10) + 8
        else:
            newlunlun1 = (lunlun * 10) + lastDigit + 1
            newlunlun2 = (lunlun * 10) + lastDigit - 1
            heapq.heappush(heap, newlunlun1)
            heapq.heappush(heap, newlunlun2)

    return heapq.heappop(heap)

k = input()
print(solve(int(k)))

Submission status: Wrong Answer

Solution code:
K = int(input())

k = 0
nums = [str(n) for n in range(1, 10)]
while K != k:
    num = nums.pop(0)
    last1 = num[len(num) - 1]
    if last1== 0:
        append_num = [last1 + str(n) for n in [0, 1]]
    elif last1 == 9:
        append_num = [last1 + str(n) for n in [8, 9]]
    else:
        append_num = [last1 + str(n) for n in range(int(last1) - 1, int(last1) + 2)]
    nums += append_num
    k += 1
else:
    print(num)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
K=int(input())
S=[[1,1,1,1,1,1,1,1,1,1]]
count=9
j=0
flagI=0
flagJ=0
flag=False
ans=""
if K<10:
    print(K)
else:
    for i in range(1,11):
        S.append([0,0,0,0,0,0,0,0,0,0])
        for j in range(10):
            if j==0:
                S[i][j]=S[i-1][0]+S[i-1][1]
            elif j==9:
                S[i][j]=S[i-1][8]+S[i-1][9]
            else:
                S[i][j]=S[i-1][j-1]+S[i-1][j]+S[i-1][j+1]
            if j!=0:
                count+=S[i][j]
                if count>K:
                    flagJ=j
                    flagI=i
                    break
                elif count==K:
                    flag=True
                    for l in range(i+1):
                        ans+=str(i+1+l)
                    break
        if flag:
            break
        if count>K:
            count-=S[flagI][flagJ]
            break
    
    #print(S)
    if flag:
        print(ans)
    else:
        #print(flagJ)
        ans+=str(flagJ)
        flagMax=count
        for i in range(1,len(S)):
            for j in range(1,10):
                if flagMax+S[len(S)-1-i][j]==K:
                    flag=True
                    for l in range(i):
                        ans+=str(j+l)
                    break
                if flagMax+S[len(S)-1-i][j]>K:
                    ans+=str(j-1)
                    break
                flagMax+=S[len(S)-1-i][j]
                
        print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
k = int(input())
q = deque(range(1,10))
while k:
    k-=1
    t=q.popleft()
    if t%10 !=0: 
      q.append(10*t+t%10-1)
      q.append(10*t+t%10)
    if t%10 !=9:
      q.append(10*t+t%10+1)
 
print(t)

Submission status: Wrong Answer

Solution code:
K = int(input())
from collections import deque
que=deque([1,2,3,4,5,6,7,8,9])
for i in range(K):
    x=que.popleft()
    if x%10!=0:
        que.append(10*x+(x%10-1))
    que.append(10*x)
    if x%10!=9:
        que.append(10*x+(x%10+1))
print(x)

Submission status: Wrong Answer

Solution code:
from collections import deque
k=int(input())
d=deque([1,2,3,4,5,6,7,8,9])
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())
#print(k)
l = [[0 for i in range(10)] for j in range(10)]

for j in range(10):
	l[0][j] = 1

for i in range(1,10):
	for j in range(10):
		if(j != 0)and(j != 9):
			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]

#print(l)
ai = 0
aj = 0
sum = 0
ret = 0
for i in range(10):
	for j in range(1,10):
		sum += l[i][j]
		if(sum >= k):
			ai = i
			aj = j
			sum -= l[i][j]
#			print("ai: ",ai,", aj: ",aj,", sum:",sum) 
			break
	if(ai != 0)or(aj != 0):
		break

ret = aj*(10**ai)
m = aj
for i in range(ai):
	if(ai-1-i < 0):
		break
	if(m != 0):
		sum += l[ai-1-i][m-1]
		if(sum >= k):
			sum -= l[ai-1-i][m-1]
			m = m-1
			ret += m*(10**(ai-1-i))
#			print("ai-1-i: ",ai-1-i," m:",m," sum:",sum," ret: ",ret,"!!") 
			continue
	
	sum += l[ai-1-i][m]
	if(sum >= k):
		sum -=l[ai-1-i][m-1]
		ret += m*(10**(ai-1-i))
#		print("ai-1-i: ",ai-1-i," m:",m," sum:",sum," ret: ",ret,"!") 
		continue
	
	m = m+1
	ret += m*(10**(ai-1-i))
#	print("ai-1-i: ",ai-1-i," m:",m," sum:",sum," ret: ",ret) 

#print("ret:",ret)
print(ret)

Submission status: Wrong Answer

Solution code:
import math

num = int(input())

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

while True:
    #boxに入っている数字がnumと同じ個数だったら終わり
    if len(box)==num:
        print(box[num-1])
        break

    k = k+1 #k=数字
    k1 = str(k)
    for i in range(len(k1)-1):
        if i == len(k1)-2:
            if abs(int(k1[i])-int(k1[i+1]))<=1:
                box.append(k)
        if abs(int(k1[i])-int(k1[i+1]))<=1:
            continue
        else:break

print(box)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

for i in range(n):
  x = list[0]
 # print(i,"番目　",x)
  list.pop(0)
  if x % 10 != 0:
    list.append(10*x + (x%10) -1)
    list.append(10*x + (x%10))
  if x % 10 != 9:
    list.append(10*x + (x%10) + 1)
print(x)

Submission status: Wrong Answer

Solution code:
import math

num = int(input())

box = []
k=0

while True:
    #boxに入っている数字がnumと同じ個数だったら終わり
    if len(box)==num:
        print(box[num-1])
        break

    k = k+1
    k1 = str(k)
    for i in range(len(k1)):
        if i == len(k1)-1:
            if abs(int(k1[i])-int(k1[i-1]))<=1:
                box.append(k)
        if abs(int(k1[i])-int(k1[i-1]))<=1:
            continue
        else:break

Submission status: Wrong Answer

Solution code:
from collections import deque

K = int(input()) 
a = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])


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

Submission status: Wrong Answer

Solution code:
from collections import deque

K = int(input()) 
a = deque()

for i in range(1,10):
    a.append(i)
    
for i in range(K):
    j = a.popleft()
    print(j)
    if j%10 != 0:
        a.append((10*j) + ((j%10) -1))
        
    a.append((10*j)+j%10)
    
    if j%10 != 9:
        a.append((10*j) +((j%10)+1))

Submission status: Wrong Answer

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