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())
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

for i in range(K):
    runrun = q.popleft()
    rem = runrun % 10
    if rem == 0:
        q.append(runrun * 10)
        q.append(runrun * 10 + rem + 1)
    elif rem == 9:
        q.append(runrun * 10 + rem - 1)
        q.append(runrun * 10)
    else:
        q.append(runrun * 10 + rem - 1)
        q.append(runrun * 10)
        q.append(runrun * 10 + rem + 1)

print(runrun)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc161/tasks/abc161_d

import sys
# sys.setrecursionlimit(100000)
import heapq


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = int(input())
    if n < 10:
        print(n)
    cnt = 0
    hq = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    while cnt < n:
        i = heapq.heappop(hq)
        cnt += 1
        if cnt == n:
            print(i)
            return
        r = int(str(i)[::-1][0])
        heapq.heappush(hq, int(str(i) + str(r)))
        if r != 9:
            heapq.heappush(hq, int(str(i) + str(r + 1)))
        if r != 0:
            heapq.heappush(hq, int(str(i) + str(r - 1)))
    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
K = int(input())
a = []

def DFS(n):
    if n > 3234566667:
        return
    a.append(n)
    l = n % 10
    if l == 0:
        DFS(10 * n)
        DFS(10 * n + 1)
    elif l == 9:
        DFS(10 * n)
        DFS(10 * n + 8)
    else:
        DFS(10 * n + l)
        DFS(10 * n + l + 1)
        DFS(10 * n + l - 1)

for i in range(1, 10):
    DFS(i)

a = sorted(a)
print(a[K-1])

Submission status: Wrong Answer

Solution code:
#D - Lunlun Number
import sys
sys.setrecursionlimit(10**6)
K = int(input())

ans = []
def dfs(A):
    if len(A)>=2:
        A_str = [str(i) for i in A] 
        A_str = ''.join(A_str)
        ans.append(int(A_str))
    if len(A) == 10:
        return
    if len(A) >= 1:
        if A[-1] != 0:
            sta = A[-1] - 1
            fin = A[-1] + 1 + 1
        else:
            sta = 0
            fin = 1+1
        for v in range(sta,fin):
            A.append(v)
            dfs(A)
            A.pop()
    else:
        for v in range(1,9+1):
            A.append(v)
            dfs(A)
            A.pop()
dfs([])
ans = sorted(ans,reverse = False)

if K<=9:
    print(K)
else:
    print(ans[K-10])

Submission status: Wrong Answer

Solution code:
#D - Lunlun Number
import sys
sys.setrecursionlimit(10**6)
K = int(input())

ans = []
def dfs(A):
    if len(A)>=2:
        A_str = [str(i) for i in A] 
        A_str = ''.join(A_str)
        ans.append(int(A_str))
    if len(A) == 10:
        return
    if len(A) >= 1:
        prev_num = A[-1]
        for v in range(abs(prev_num-1),abs(prev_num+1)+1):
            A.append(v)
            dfs(A)
            A.pop()
    else:
        for v in range(1,9):
            A.append(v)
            dfs(A)
            A.pop()
dfs([])
ans = sorted(ans,reverse = False)
if K<=9:
    print(K)
else:
    print(ans[K-10])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import queue

Submission status: Wrong Answer

Solution code:
k=int(input())
cnt=0
ans=0
if k<=9:
    print(k)

else:
    cnt=9
    for i in range(10,10**5):
        ans=0
        for j in range(0,7):
            if j<=len(str(i))-2:
                if abs(int((str(i))[j+1])-(int((str(i))[j])))<=1:
                    ans+=1
                else:
                    ans=0
        
            else:
                if ans==j:
                    cnt+=1
                    if cnt==k:
                        print(str(i))        
                        break
        else:
            continue
        break

Submission status: Wrong Answer

Solution code:
K=int(input())
import queue
q=queue.Queue()
for i in range(1,10):
  q.put(i)
for j in range(1,K+1):
  x=q.get(j)
  if x%10!=0:
    q.put(10*x+x%10-1)
    q.put(10*x+x%10)
  if x%10!=9:
    q.put(10*x+x%10+1)
print(x)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from heapq import *

a = [*range(1, 10)]
heapify(a)
i = 0
k = int(input())
c = 0
while True:
    t = str(heappop(a))
    i += 1
    if i == k:
        break
    if t[-1] != "0":
        heappush(a, int(t + str(int(t[-1]) - 1)))
    heappush(a, int(t + t[-1]))
    if t[0] != "9":
        heappush(a, int(t + str(int(t[-1]) + 1)))
print(t)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil, log
def main():
    k = int(input())
    k2 = int(log(ceil(k / 10), 3)) + 1
    def getlun(n, keta, first):
        if keta > k2:
            pass
        else:
            l1 = 10 ** (keta + 1) * first + n
            lunluns.append(l1)
            getlun(l1, keta + 1, first)
            if first > 1:
                l2 = 10 ** (keta + 1) * (first - 1) + n
                lunluns.append(l2)
                getlun(l2, keta + 1, first - 1)
            if first < 9:
                l3 = 10 ** (keta + 1) * (first + 1) + n
                lunluns.append(l3)
                getlun(l3, keta + 1, first + 1)
    lunluns = [i for i in range(1, 11)]
    for i1 in range(1, 10):
        getlun(i1, 0, i1)
    getlun(10, 1, 1)
    lunluns.sort()
    print(lunluns[k-1])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil
def main():
    k = int(input())
    k2 = ceil(k / 10)
    def getlun(n):
        ns = str(n)
        if len(ns) > k2 - 1:
            pass
        else:
            ns1 = int(ns[0])
            l1 = ns[0] + ns
            lunluns.append(int(l1))
            getlun(int(l1))
            if ns1 > 1:
                l2 = str(ns1 - 1) + ns
                lunluns.append(int(l2))
                getlun(int(l2))
            if ns1 < 9:
                l3 = str(ns1 + 1) + ns
                lunluns.append(int(l3))
                getlun(int(l3))
    lunluns = [i for i in range(1, 11)]
    for i1 in range(1, 11):
        getlun(i1)
    lunluns.sort()
    print(lunluns[k-1])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

k = int(input())


if k < 10:
    print(k)
    # exit()

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

cnt = 9
while cnt < k:
    x = q.popleft()
    if x % 10 == 0:
        nx = 10 * x
        q.append(nx)
        lun.append(nx)
        nx = 10 * x + 1
        q.append(nx)
        lun.append(nx)
        cnt += 2
    elif x % 10 == 9:
        nx = 10 * x + 8
        q.append(nx)
        lun.append(nx)
        nx = 10 * x + 9
        q.append(nx)
        lun.append(nx)
        cnt += 2
    else:
        m = x % 10
        nx = 10 * x + m - 1
        q.append(nx)
        lun.append(nx)
        nx = 10 * x + m
        q.append(nx)
        lun.append(nx)
        nx = 10 * x + m + 1
        q.append(nx)
        lun.append(nx)
        cnt += 3
lun.sort()
print(lun[k-1])

Submission status: Wrong Answer

Solution code:
from collections import deque

n = int(input())
q = deque(range(1, 10))
for _ in range(n - 1):
    x = q.popleft()
    r = x % 10
    y = 10 * x
    if r == 0:
        q.extend([y, y+1, y+9])
    elif r == 9:
        q.extend([y, y+8, y+9])
    else:
        q.extend([y+r-1, y+r, y+r+1])
print(q.popleft())

Submission status: Wrong Answer

Solution code:
order=int(input())
total_list=[]
keta_list=[]
sample_sum=1
i=0
while sample_sum<order+1:
    total_list.append(sample_sum)
    i+=1
    if i==1:
        keta_n=[1,1,1,1,1,1,1,1,1,1]
    else:
        keta_n_one=keta_list[-1]
        keta_n=[]
        for i in range(10):
            if i==0:
                keta_n.append(keta_n_one[0]+keta_n_one[1])
            elif i==9:
                keta_n.append(keta_n_one[i]+keta_n_one[i-1])
            else:
                keta_n.append(keta_n_one[i-1]+keta_n_one[i]+keta_n_one[i+1])
    sample_sum+=sum(keta_n[1:])
    keta_list.append(keta_n)

keta=len(keta_list)

order=order-total_list[keta-1]+1

def function(order,keta,top,pre):
    keta_res_num=keta_list[keta-1]
    check=0
    i=-1
    while check<order:
        i+=1
        if top==True and i==0:
            i=1
        elif top==False and i==0:
            i=pre-1
        check+=keta_res_num[i]        
    top_num=i
    order-=check-keta_res_num[i]
    return top_num,order


ans=[]
i=0
while keta:
    i+=1
    if i==1:
        top,order=function(order,keta,True,pre=None)
    else:
        top,order=function(order,keta,False,pre=top)
    ans.append(str(top))
    keta-=1
print("".join(ans))

Submission status: Wrong Answer

Solution code:
k = int(input())
cur = [[1]*10 for i in range(11)]
if k <= 9:
  print(k)
  exit()
c = 9
i = 0
while c < k:
  i += 1
  for j in range(10):
    cur[i][j] = cur[i-1][j]
    if j != 0:
      cur[i][j] += cur[i-1][j-1]
    if j != 9:
      cur[i][j] += cur[i-1][j+1]
  if sum(cur[i]) >= k:
    break
  else:
    c += sum(cur[i][1:])
ans = ''
for j in range(i,-1,-1):
  for l in range(10):
    if j == i and l == 0:
      continue
    if j != i and abs(l-int(ans[-1])) > 1:
      continue
    if c + cur[j][l] >= k:
      ans += str(l)
      break
    else:
      c += cur[j][l]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
import heapq
k = int(input())
s =[1,2,3,4,5,6,7,8,9,10]
heapq.heapify(s)
li = []
while len(li)<=100000:
    val = heapq.heappop(s)
    li.append(val)
    if str(val)[0]=='1':
        heapq.heappush(s,int(str(1) + str(val)))
        heapq.heappush(s,int(str(2) + str(val)))
        heapq.heappush(s,int(str(1) + str(0) + str(val)))
    else:
        heapq.heappush(s,int(str(int(str(val)[0])+1) + str(val)))
        heapq.heappush(s,int(str(int(str(val)[0])-1) + str(val)))
        heapq.heappush(s,int(str(int(str(val)[0])) + str(val)))
li.sort()
print(li[k-1])

Submission status: Wrong Answer

Solution code:
k=int(input())
d=[]
def nex(x,y):
  if x==0:return [0,1,9][y]
  elif x==9:return ([0,8,9][y])
  else: return x+y-1
  
i=0
s=0
so=0
while k>s:#桁数決定
  i+=1
  so=s
  s=9*(3**i-1)//2
  #print(i,s,9*3**(i-1))
p=(k-so-1)//3**(i-1)+1#一桁目
a=k-so-(3**(i-1))*(p-1)
d.append(p)
#print(p,k,a,so)

if i==1:print(k)
while i>1: 
  i-=1
  p=(a-1)//3**(i-1)
  a=a-p*3**(i-1)

  #print(d[-1],p,a)
  d.append(nex(d[-1],p))
 
print("".join(map(str,d)))

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

k = INT()
s = list('00000000000')

for i in range(k):
    for j in range(len(s)):
        if s[j] != '9' and ( s[j+1] == '0' or int(s[j]) < int(s[j+1]) + 1 ):
            s[j] = str(int(s[j]) + 1)
        else:
            continue

        while j > 0:
            j -= 1
            s[j] = str(max(0, int(s[j+1])-1))
        break

ans = int("".join(reversed(s)))
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    k = int(input())
    hp = [i for i in range(k+4)]
    r, w = 1, 10
    while w < k:
        n = hp[r]
        r += 1
        nm = n % 10
        val = n * 10 + nm
        
        if nm != 0:
            hp[w] = val - 1
            w += 1
        hp[w] = val
        w += 1
        if nm != 9:
            hp[w] = val + 1
            w += 1

    print(hp[k])

main()

Submission status: Wrong Answer

Solution code:
def main():
    k = int(input())
    hp = list(range(1, 10))
    for i in range(k-1):
        n = hp.pop(0)
        if n % 10 != 0:
            hp.append(n * 10 + n - 1)
        hp.append(n * 10 + n)
        if n % 10 != 9:
            hp.append(n * 10 + n + 1)
    print(hp[0])

Submission status: Wrong Answer

Solution code:
def runrun(i):
    if i < 13:
        return True, 0
    i = str(i)
    for digit in range(len(i) - 1):
        if abs(int(i[digit]) - int(i[digit + 1])) > 1:
            break
    else:
        return True, 0
    return False, digit


K = int(input())
i = 1
cnt = 0
while True:
    boo, dig = runrun(i)
    cnt += boo
    if cnt == K:
        break
    i += 10 ** dig
print(i)

Submission status: Wrong Answer

Solution code:
import copy
k = int(input())
c = 10
ans = 0
if k <= 10:
	print(k)
else:
	while c < k:
		C = copy.copy(list(str(c)))
		ok = 0
		for i in range(len(C)-1):
			if abs(int(C[i]) - int(C[i+1])) <= 1:
				ok += 1
		if ok == len(C) - 1:
			ans += 1
		c += 1
	print(c+8)

Submission status: Wrong Answer

Solution code:
import copy
k = int(input())
c = 10
ans = 0
if k <= 10:
	print(k)
else:
	while ans < k:
		C = copy.copy(list(str(c)))
		ok = 0
		for i in range(len(C)-1):
			if abs(int(C[i]) - int(C[i+1])) <= 1:
				ok += 1
		if ok == len(C) - 1:
			ans += 1
		c += 1
	print(ans + 8)

Submission status: Wrong Answer

Solution code:
k=int(input())

que=list(range(1,9+1))

while True:
 k-=len(que)
 for q in que[:]:
    que.remove(q)
    lq=int(str(q)[-1])
    for r in (lq-1,lq,lq+1):
        if 0<=r<=9:
            que.append(int(str(q)+str(r)))
 # print(que)
 
 if len(que)>=k:
    break
 
que.sort()
print(que[k-1])

Submission status: Wrong Answer

Solution code:
def lulun_generator():
    x = 0
    while True:
        x += 1
        str_x = str(x)
        c = 0
        for k in range(len(str_x)-1):
            if abs(int(str_x[k])-int(str_x[k-1])) < 2:
                c += 1
            else:
                break
        if c == len(str_x)-1:
            yield x

K = int(input())

i = 0
for l in lulun_generator():
    i += 1
    if(i==K):
        print(l)
        quit()

Submission status: Wrong Answer

Solution code:
def lulun_generator():
    x = 0
    while True:
        x += 1
        str_x = str(x)
        c = 0
        for k in range(len(str_x)-1):
            if abs(int(str_x[k])-int(str_x[k-1])) < 2:
                c += 1
        if c == len(str_x)-1:
            yield x
            continue



K = int(input())

i = 0
lc = 0
for l in lulun_generator():
    i += 1
    if(i==K):
        print(l)
        quit()

Submission status: Wrong Answer

Solution code:
K = int(input())

cnt = 0
while cnt <= K:
    for i in range(1, 10 ** 5):
        j = str(i)
        L = list(map(int, j))
        L = L[::-1]
        if len(L) == 1:
            cnt += 1
            if i == K:
                print(i)
                exit()
            else:
                continue
        else:
            for j in range(1, len(L)):
#                print(L[j], L[j - 1],L[j] - L[j - 1])
                if abs(L[j] - L[j - 1]) > 1:
                    cnt -= 1
                    break
            cnt += 1
            if cnt == K:
                print(i)
                exit()

Submission status: Wrong Answer

Solution code:
from collections import deque
K = int(input())
d = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

if K <= 9:
  print(K)
else:
  i = 9
  while i < K:
    num = d[0]
    plus = int(10*num + num%10)
    d.append(plus-1)
    i += 1
    if i < K:
      d.append(plus)
      i += 1
    if i < K:
      d.append(plus+1)
      d.popleft()
      i += 1
  else:
    print(d[-1])

Submission status: Wrong Answer

Solution code:
from collections import deque


def solver(K):
    q = deque([i for i in range(1, 10)])

    if K <= 9:
        ans = q[K - 1]

    else:
        cnt = 9
        for i in range(1, K):
            c = q.popleft()

            q.append(c * 10 + (c % 10))
            cnt += 1
            if cnt >= K:
                break

            if c % 10 != 0:
                q.append(c * 10 + (c % 10) - 1)
                cnt += 1
                if cnt >= K:
                    break

            if c % 10 != 9:
                q.append(c * 10 + (c % 10) + 1)
                cnt += 1
                if cnt >= K:
                    break


        ans = q[-1]
    return ans


def run():
    K = int(input())
    ans = solver(K)

    print(ans)


run()

Submission status: Wrong Answer

Solution code:
from collections import deque


def solver(K):
    q = deque([i for i in range(1, 10)])

    if K <= 9:
        ans = q[K - 1]

    else:
        cnt = 9
        for i in range(1, K):
            c = q.popleft()

            # 1小さい数字
            q.append(c * 10 + (c % 10))
            if c % 10 != 0:
                q.append(c * 10 + (c % 10) - 1)
                cnt += 1
                if cnt >= K:
                    break

            # 同じ数字
            q.append(c * 10 + (c % 10))
            cnt += 1
            if cnt >= K:
                break

            # 1大きい数字
            if c % 10 != 9:
                q.append(c * 10 + (c % 10) + 1)
                cnt += 1
                if cnt >= K:
                    break

        ans = q[-1]
    return ans


def run():
    K = int(input())
    ans = solver(K)

    print(ans)


run()

Submission status: Wrong Answer

Solution code:
from collections import deque


def solver(K):
    q = deque([i for i in range(1, 10)])

    if K <= 9:
        ans = q[K - 1]

    else:
        cnt = 9
        for i in range(1, K):
            c = q.popleft()

            # 同じ数字
            q.append(c * 10 + (c % 10))
            cnt += 1
            if cnt >= K:
                break

            # 1小さい数字
            q.append(c * 10 + (c % 10))
            if c % 10 != 0:
                q.append(c * 10 + (c % 10) - 1)
                cnt += 1
                if cnt >= K:
                    break

            # 1大きい数字
            if c % 10 != 9:
                q.append(c * 10 + (c % 10) + 1)
                cnt += 1
                if cnt >= K:
                    break

        ans = q[-1]
    return ans


def run():
    K = int(input())
    ans = solver(K)

    print(ans)


run()

Submission status: Wrong Answer

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

ans = []
for j in range(len(cand)):
  for val in cand[i]:
    ans.append(val)
ans = sorted(ans)

print(ans[k - 1])

Submission status: Wrong Answer

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

ans = []
for j in range(len(cand)):
  for val in cand[i]:
    ans.append(val)
ans = sorted(ans)

print(ans[k - 1])

Submission status: Wrong Answer

Solution code:
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

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

k = int(input())

cnt = [[str(i)] for i in range(10)]

d = 2
# from functools import reduce
total = 9
while total <= k:
    new_cnt = [[] for i in range(10)]
    for i in range(10):
        if i - 1 >= 0:
            new_cnt[i].append(str(i) + cnt[i - 1][-1])
        if i + 1 < 10:
            new_cnt[i].append(str(i) + cnt[i + 1][-1])
        new_cnt[i].append(str(i) + cnt[i][-1])

        if i != 0:
            total += len(new_cnt[i])
    for i in range(10):
        cnt[i] += new_cnt[i]

ans = sorted(map(int, sum(cnt[1:10], [])))
print(ans[k - 1])

Submission status: Wrong Answer

Solution code:
k = int(input())

n = 1
cnt = 0
while True:
    s = str(n)
    for i in range(len(s) - 1):
        if not int(s[i + 1]) in [int(s[i]), int(s[i]) - 1, int(s[i]) + 1]:
            n += 10 ** (len(s) - i)
            n = (n // (10 ** (len(s) - i - 1))) * (10 ** (len(s) - i - 1))
            break
    else:
        cnt += 1
    if cnt == k:
        break
    n += 1

print(n)

Submission status: Wrong Answer

Solution code:
from collections import deque
que=deque([i for i in range(1,10)])
k=int(input())
count=0
while count!=k:
  a=que.popleft()
  count+=1
  if a%10==9:
    que.extend([10*a+8,10*a+9])
  else:
    b=a*10+(a%10)-1
    que.extend([b,b+1,b+2])
print(a)

Submission status: Wrong Answer

Solution code:
from collections import deque
que=deque([i for i in range(1,10)])
k=int(input())
count=0
while count!=k:
  a=que.popleft()
  count+=1
  if a%10==1:
    que.extend([10*a+1,10*a+2])
  elif a%10==9:
    que.extend([10*a+8,10*a+9])
  else:
    b=a*10+(a%10)-1
    que.extend([b,b+1,b+2])
print(a)

Submission status: Wrong Answer

Solution code:
def generate(n):
    if n == 1:
        for i in range(1, 10):
            yield [i]
    else:
        for A in generate(n - 1):
            for i in range(10):
                if abs(A[-1] - i) <= 1:
                    yield A + [i]


L = []
for n in range(1, 11):
    for A in generate(n):
        L.append(int(''.join([str(a) for a in A])))
print(len(L))
k = int(input())
print(L[k - 1])

Submission status: Wrong Answer

Solution code:
import sys
# from collections import defaultdict
# from collections import Counter
from queue import Queue
# sys.setrecursionlimit(2000000)

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

    queue = Queue()
    for i in [ 1, 2, 3, 4, 5, 6, 7, 8, 9, ]:
        queue.put(i)

    for i in range(1, K+1):
        lunlun = queue.get()
        digit = lunlun % 10

        new_lunluns = []
        if digit == 0:
            new_lunluns.append(lunlun * 10 + digit)
            new_lunluns.append(lunlun * 10 + digit + 1)
        elif digit == 9:
            new_lunluns.append(lunlun * 10 + digit)
            new_lunluns.append(lunlun * 10 + digit - 1)
        else:
            new_lunluns.append(lunlun * 10 + digit - 1)
            new_lunluns.append(lunlun * 10 + digit)
            new_lunluns.append(lunlun * 10 + digit + 1)

        for new_lunlun in new_lunluns:
            queue.put(new_lunlun)

    print(lunlun)
    return 0

if __name__ == '__main__':
    sys.exit(main())

Submission status: Wrong Answer

Solution code:
k = int(input())

class Myqueue:
  def __init__(self):
    self.queue = []
    
  def enqueue (self, item):
    self.queue.append(item)
  
  def dequeue (self):
    if len(self.queue) ==0:
      return None
    result =self.queue[0]
    del self.queue[0]
    return result

myq = Myqueue()
myq.enqueue(1)
myq.enqueue(2)
myq.enqueue(3)
myq.enqueue(4)
myq.enqueue(5)
myq.enqueue(6)
myq.enqueue(7)
myq.enqueue(8)
myq.enqueue(9)

K = 9
s = 9
if k < 10:
  print(k)
elif k >= 10:
  while s <= k:
    x = myq.dequeue()
    I = x % 10
    if I == 0:
      myq.enqueue(x*10 + I)
      myq.enqueue(x*10 + (I+1))
      s += 2
    elif I ==9:
      myq.enqueue(x*10 + (I-1))
      myq.enqueue(x*10 + I)
      s += 2
    else:
      myq.enqueue(x*10 + (I-1))
      myq.enqueue(x*10 + I)
      myq.enqueue(x*10 + (I+1))
      s += 3

if s - 2 == k:
  print(myq.queue[-3])
elif s - 1 == k:
  print(myq.queue[-2])
elif s == k:
  print(myq.queue[-1])
else:
  print(myq.queue[-4])

Submission status: Wrong Answer

Solution code:
n = int(input())

Submission status: Wrong Answer

Solution code:
K = int(input())
counter = [1,2,3,4,5,6,7,8,9,10]
while len(counter) < K:
  n = str(counter[-1]+1)
  if int(n[-1]) in [int(n[-2])-1,int(n[-2]),int(n[-2])+1]:
    counter.append(int(n))
print(counter[-1])

Submission status: Wrong Answer

Solution code:
K = int(input())
counter = [1,2,3,4,5,6,7,8,9,10]
while len(counter) < K:
  n = str(counter[-1]+1)
  if int(n[-1]) in [int(n[-2])-1,int(n[-2]),int(n[-2])+1]:
    counter.append(int(n))
print(counter)

Submission status: Wrong Answer

Solution code:
k = int(input())
count = 0
queue = []
for i in range(1,10):
    queue.append(i)
if k <= 12:
    print(k)
else:
    while count < k:
        t = str(queue.pop(0))
        s = int(t[-1])
        queue.append(int(t)*10 + s - 1)
        queue.append(int(t)*10 + s)
        queue.append(int(t)*10 + s + 1)
        count += 1
    print(int(t))

Submission status: Wrong Answer

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

if k <= 12:
    print(k)
else:
    x = ((11 * (int((k-12)/3)) + 12))
    if (k-12) % 3 == 0:
        print(x)
    elif (k-12) % 3 == 1:
        print(x+9)
    else:
        print(x+10)

Submission status: Wrong Answer

Solution code:
k = int(input())

if k <= 12:
    print(k)
else:
  print((11 *  ((k - 12) / 3)) + 9 + ((k - 12) % 3)-1)

Submission status: Wrong Answer

Solution code:
k = int(input())

if k < 10:
    print(k)
else:
    count = 9
    ans = 0
    while count < k:
        ans += 1
        judge = 1
        for keta in range(1,len(str(ans))):
            #tmp = str(ans)
            judge *= abs(int(str(ans)[keta])-int(str(ans)[keta-1]))+1
            if abs(judge) <= 2**(len(str(ans))-1):
                count += 1
                #print(ans) #test
                if count == k:
                    print(ans)
                    break

Submission status: Wrong Answer

Solution code:
k = int(input())

if k < 10:
    print(k)
else:
    count = 9
    ans = 0
    while count < k:
        ans += 1
        judge = 1
        for keta in range(1,len(str(ans))):
            #tmp = str(ans)
            judge *= int(str(ans)[keta])-int(str(ans)[keta-1])
            if abs(judge) <= 1:
                count += 1
                #print(ans) #test
                if count == k:
                    print(ans)
                    break

Submission status: Wrong Answer

Solution code:
from collections import deque
K = int(input())
que = deque()
que.extend([i for i in range(1,10)])

for k in range(K-2):
    out = que.popleft()
    div = out%10
    if div==0:
        que.extend([out*10,out*10+1])
    elif out%10==9:
        que.extend([out*10+8,out*10+9])
    else:
        que.extend([out*10-1+div,out*10+div,out*10+1+div])
print(que.popleft())

Submission status: Wrong Answer

Solution code:
_input = input
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

#ここに書きたいコードを書く
#データ読み込み
K=int(input())

bansu=10
n=9

while bansu <= K:
	n += 1
	n_str = str(n)
	l=len(n_str)
	lun_flag = True
	for i in range(l-1):
		if abs(int(n_str[i]) - int(n_str[i+1])) >     1:
			lun_flag = False
	
	#print(n,bansu,lun_flag)
	
	if lun_flag == True:
		bansu += 1
	
print(n)
		
	

input = _input

Submission status: Wrong Answer

Solution code:
from collections import deque
num=deque([1,2,3,4,5,6,7,8,9])
cnt=0
K=int(input())
while(True):
    a=num.popleft()
    cnt+=1
    if cnt==K:
        print(a)
        exit()
    if a%10!=0:
        a1=10*a+(a%10)-1
    a2=10*a+a%10
    if a%10!=9:
        a3=10*a+a%10 +1
    num.append(a1)
    num.append(a2)
    num.append(a3)

Submission status: Wrong Answer

Solution code:
k = int(input())
stack = list(range(1,10))
for i in range(k):
  num = stack.pop(0)
  #print(num)
  if (m:=num%10) == 0:
    stack+=[num*10 + m,num*10+m+1]
  elif m == 9:
    stack+=[num*1 + m -1,num*10 + m]
  else:
    stack +=[num*10 + m -1,num*10 + m, num*10+ m + 1]
print(num)

Submission status: Wrong Answer

Solution code:
#D
k = int(input())
if k <= 9:
    print(k)
else:
    a = (k - 9 - 0.5) // 3 + 1#何列目か．
    b = (k - 10) % 3#何番目か
    lun = [10, 11, 12]
    print(int(lun[b] + 11 * (a - 1)))

Submission status: Wrong Answer

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    k = ni()

    que = queue.Queue()

    if k < 11:
        print(k)
        exit(0)

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

    cnt = 19
    flg = True
    while flg:
        tmp = que.get()
        grade1 = tmp % 10

        for i in (-1, 0, 1):
            if -1 < grade1 + i < 10:
                que.put(tmp * 10 + grade1 + i)
                cnt += 1
                if cnt == k:
                    print(tmp * 10 + grade1 + i)

                    exit(0)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    import collections
    K = int(input())

    que = collections.deque(list(range(1,10)))

    cnt = 0
    
    while cnt < K:
        cnt += 1
        temp = que.popleft()

        push1 = temp*10 + temp%10 - 1
        push2 = temp*10 + temp%10
        push3 = temp*10 + temp%10 + 1

        push_list = [push1, push2, push3]
        for push_num in push_list:
            if len(str(push_num)) == len(str(temp)) + 1:
                que.append(push_num)
        
        # print(temp)


    print(temp)



if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
K = int(input())
li = []

def is_ok(n):
    n = str(n)
     
    array = list(map(int,n))

    cnt = 0
    for i in range(len(array)):
        if abs(array[i]-array[i-1])<2:
            cnt+=1
    return cnt ==len(array)
i = 1
while len(li) != K:
    if is_ok(i):
        li.append(i)
    i+=1
print(sorted(li)[-1])

Submission status: Wrong Answer

Solution code:
K=int(input())
ans=0
runrun = 0
i =1
while runrun < K:
    if i < 10:
        runrun +=1
        ans = i
    else:
        a = list(map(int,str(i)))
        for j in range(1,len(a)):
            tmp = False
            if abs(a[j]-a[j-1]) > 1:
                continue
            runrun +=1
            ans = i 
    i +=1
print(ans)