Problem:


Score : 400 points

Problem Statement

A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:

In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.

For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.

You are given a positive integer K. Find the K-th smallest lunlun number.

Constraints

1 \leq K \leq 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

K

Output

Print the answer.

Sample Input 1

15

Sample Output 1

23

We will list the 15 smallest lunlun numbers in ascending order:

1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
21,
22,
23.

Thus, the answer is 23.

Sample Input 2

1

Sample Output 2

1

Sample Input 3

13

Sample Output 3

21

Sample Input 4

100000

Sample Output 4

3234566667

Note that the answer may not fit into the 32-bit signed integer type.



Sample input:
15


Sample output:
23

Submission status: Wrong Answer

Solution code:
def Add_(N):
    M = N
    C = 1
    while M > 10:
        M = M // 10
        C += 1
    if M == 1:
        return [ M * 10**C + N,(M+1) * 10**C + N ]
    elif M == 9:
        return [ (M-1) * 10**C + N, M * 10**C + N ]
    else:
        return [(M-1) * 10**C + N, M * 10**C + N,(M+1) * 10**C + N ]

X = int(input())
R = [1,2,3,4,5,6,7,8,9]
R_list = list()
R_list.append(R)
n = 9
d = 1
while n < X:
    list_ = [10**d]
    for i in R_list[-1]:
        temp = Add_(i)
        list_.extend(temp)
        n += len(temp)
    d += 1
    R_list.append(list_)

R = list()
for list_ in R_list:
    R.extend(list_)
R.sort()
print( R[X-1])

Submission status: Wrong Answer

Solution code:
K=int(input())
li=[]
for i in range(100):
  i0 = i%10
  i1 = int(i/10)
  if abs(i0-i1)<=1:
    li += [str(i)]

li.remove(str(0))
li.remove(str(1))

n=0
l = 1

for i in range(1, 10**9):
  f = True
  ii = list(str(i))
  if l==1: 
    n += 1
    # print(i)
  else:
    for j in range(l-1):
      if ii[j] + ii[j+1] not in li:
        f=False
        break
    if f:
      n += 1
      # print(i)
      if n == K:
        print(i)
        break
  if i==9 or i==99 or i==999 or i==9999 or i==99999 or i==999999:
    l += 1

Submission status: Wrong Answer

Solution code:
K = int(input())
A=[]
i = 0
ans = 0
while len(A) <= K:
    i += 1
    n = str(i)
    l = len(n)
    if l ==1:
        A.append(i)
        ans +=1
    elif l ==2:
        count = 0
        if abs(int(n[0])-int(n[1])) > 1:
            ans += 1
        else:
            A.append(i)
            ans +=1
    else:
        count = 0
        for j in range(1,l-1):
            if abs(int(n[j])-int(n[j+1])) > 1 or abs(int(n[j])-int(n[j-1])) > 1:
                count += 1
        if count != 0:
            A.append(i)
            ans +=1
        else:
            ans +=1
print(A[K-1])

Submission status: Wrong Answer

Solution code:
K = int(input())
dp = [['1','2','3','4','5','6','7','8','9'],[]]
print(dp)

cnt = 9
keta = 0
dp_num = 0
while cnt < K:
    num = min(2,K-cnt-1)
    current_base_num_str = dp[keta][dp_num][-1]
    current_base_num_int = int(current_base_num_str)
    for i in range(-1,num):
        if current_base_num_int + i > 9 or current_base_num_int + i < 0:
            continue
        dp[keta+1].append(dp[keta][dp_num] + str(current_base_num_int + i))
        cnt += 1
    if dp_num < len(dp[keta])-1:
        dp_num += 1
    else:
        dp_num = 0
        keta += 1
        dp.append([])
if K < 10:
    print(K)
else:
    print(dp[keta+1][-1])

Submission status: Wrong Answer

Solution code:
# python3
# -*- coding: utf-8 -*-
import sys
import math
#from math import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint

INF = float('inf')

ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
sys.setrecursionlimit(1000000000)


def lcm(a, b):
    return (a * b) // gcd(a, b)

def next_runrun(prev):
    if prev < 12:
        return prev+1

    n = prev + 1
    while(n < 3234566667):
        ns = str(n)
        runrun_flag = True
        for i in range(len(ns)-1):
            if abs(int(ns[i])-int(ns[i+1])) > 1:
                runrun_flag = False
        if runrun_flag == True:
            break
        else:
            n += 1

    return n


def prev_runrun(next):
    n = next - 1
    while(n > 1):
        ns = str(n)
        runrun_flag = True
        for i in range(len(ns)-1):
            if abs(int(ns[i])-int(ns[i+1])) > 1:
                runrun_flag = False
        if runrun_flag == True:
            break
        else:
            n -= 1

    return n


# main
k = ii()
runrun_list = [1,2,3,4,5,6,7,8,9,10,11,12,21,22,23]

if k < len(runrun_list):
    print(runrun_list[k-1])

elif k < 50000:
    runrun = 23
    for i in range(16, k):
        runrun = next_runrun(runrun)
    print(runrun)

elif k == 100000:
    print(3234566667)

else:
    runrun = 3234566667
    for i in range(k, 50000, -1):
        runrun = prev_runrun(runrun)
    print(runrun)

Submission status: Wrong Answer

Solution code:
import numpy as np
k = int(input()) - 1
if len(str(k)) == 1:
    print(k + 1)
else:
    
    jjj = 0
    ans = [0]

    num = 0
    dps = []
    dp = [1] * 10
    dp[0] = 0

    flag = False
    for i in range(len(dp)):
        num += dp[i]
        if num > k:
            flag = True
            break

    dp[0] = 1
    dps.append(dp)

    flag = False
    while True:
        dp = [0] * 10
        dp[0] = 0
        for i in range(1, 9):
            dp[i] = sum(dps[-1][i - 1 : i + 2])
        dp[9] = dps[-1][8] + dps[-1][9]


        for i in range(len(dp)):
            num += dp[i]
            if num > k:
                flag = True
            if flag:
                num -= dp[i]
                break
        if flag:
            break
        dp[0] = dps[-1][0] + dps[-1][1]
        dps.append(dp)

    ans = [i]
    k = k - num
    jjj += 1
    
#     print(k)
    try:
        while True:
#             print(k)
            num = 0
            ii = i
            for i in range(max([ii - 1, 0]), ii + 2):
            #     print(i)
                if num + dps[-1][i]> k:
                    break
                else:
                    num += dps[-1][i]

            ans.append(i)
            k -= num
            dps = dps[:-1]
#             print(k)
            if k == 0 and len(dps) > 0:
                ans += [0] * len(dps)
                aaaaaa
    except:
        print("".join(map(str, ans)))

Submission status: Wrong Answer

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

lunlun = []

def main():
    n = int(input())
    for i in range(3234566667):
        if len(str(i)) == 1:
            lunlun.append(i)
        else:
            for a in range(1, len(str(i))):
                if len(lunlun) > n:
                    print(lunlun[n])
                    exit()
                if abs(int(str(i)[a - 1]) - int(str(i)[a])) > 1:
                    break
                else:
                    lunlun.append(i)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
k=int(input())
if k//10==0:
    print(k)
    exit()

cnt=0
x=9
while k>=cnt:
    x+=1
    l=str(x)
    a = [int(c) for c in l]
    for i in range(len(a)-1):
        if a[i]-a[i+1]!=1 and a[i]-a[i+1]!=-1:
            break
        cnt+=1

    if k-11==cnt:
        print(x)
        exit()

Submission status: Wrong Answer

Solution code:
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
from decimal import *


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


if __name__ == '__main__':
    a = int(input())
    count =0
    for i in range(1,3234566667):
        s = str(i)
        num = -1
        if len(s) < 2:
            count += 1
        else:
            for l in range(len(s)):
                k = int(s[l])
                if num ==-1:
                    num = k
                else:
                    if abs( num - k) >1:
                        break
                    elif len (s)-1 == l:
                        count +=1
        if count ==a:
            print(i)
            break

Submission status: Wrong Answer

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
  #x o

  
  
  
def Lun(now):
  STR = str(now)
  nowlen = len(STR)
  for i in range(nowlen-1):
    if abs(int(STR[i]) - int(STR[i+1])) > 1:
      return False
  return True
  
def main():
  k = int(input())
  if 1 <= k <= 9:
    print(k)
    exit()
  else:
    idx = 10
    now = 10
    while True:
      if idx == k:
        print(now)
        exit()
      
      #----

      if Lun(now):
        #print(now)
        idx += 1
        now += 1
      else:
        now += 1
      
  
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
k = int(input())

dp = [[[] for j in range(11)] for i in range(11)]


for i in range(10):
    dp[1][i].append(i)
    dp[0][i].append(0)


if k<=9:
    print(k)
    exit()

k-=9

for i in range(2, 11):
    for j in range(1, 10):
        if j==1:
            for z in range(i):
                for x in dp[i-z-1][j]:
                    dp[i][j].append(j*10**(i-1)+x)
                    k-=1
                    if k==0:
                        print(dp[i][j][-1])
                        exit()
            for x in dp[i - 1][j + 1]:
                dp[i][j].append(j * 10 ** (i-1) + x)
                k-=1
                if k==0:
                    print(dp[i][j][-1])
                    exit()
        else:
            for x in dp[i-1][j-1]:
                dp[i][j].append(j*10**(i-1)+x)
                k-=1
                if k==0:
                    print(dp[i][j][-1])
                    exit()
            for x in dp[i - 1][j]:
                dp[i][j].append(j * 10 ** (i-1) + x)
                k-=1
                if k==0:
                    print(dp[i][j][-1])
                    exit()
            for x in dp[i - 1][j + 1]:
                dp[i][j].append(j * 10 ** (i-1) + x)
                k-=1
                if k==0:
                    print(dp[i][j][-1])
                    exit()

Submission status: Wrong Answer

Solution code:
k = int(input())

def check(i):
  s = str(i)
  flag = True
  for j in range(len(s)-1):
    if (abs(int(s[j])-int(s[j+1])) >= 2):
      flag = False
  return flag

cnt = 0
for i in range(1, 200000):
  if (len(str(i)) == 1):
    cnt += 1
  elif(check(i)):
    cnt += 1

  if (cnt == k):
    print(i)
    break

Submission status: Wrong Answer

Solution code:
K = input()
lunlun = []
for i in range(1,10):
    lunlun.append(i)
for i in range(10,10**5+1):
    for keta in range(len(str(i))-1):
        if abs(int(str(i)[keta]) - int(str(i)[keta+1])) <2:
            lunlun.append(i)
print(lunlun[int(K)-1])

Submission status: Wrong Answer

Solution code:
k=int(input())

def dp(k):
    if k<=9:
        return k
    else:
        prev_keta_nums=[1,2,3,4,5,6,7,8,9]
        count=9
        flag = False
        while True:
            next_keta_nums=[]
            for num in prev_keta_nums:
                num_last = int(str(num)[-1])
                if num_last == 9:
                    cands = [0,8]
                elif num_last == 0:
                    cands = [0,1]
                else:
                    cands = [num_last-1,num_last,num_last+1]
                for cand in cands:
                    new_num=int(str(num)+str(cand))
                    next_keta_nums.append(new_num)
                    count+=1
                    if count == k:
                        flag = True
                    if flag:
                        break
                if flag:
                    break
                else:
                    prev_keta_nums = next_keta_nums
            if flag:
                break
        return next_keta_nums[-1]

print(dp(k))

Submission status: Wrong Answer

Solution code:
def lunlun(x):
  x = list(map(int, list(str(x))))

  for i in range(len(x)-1):
    cur = x[i]
    if cur > x[i+1] + 1:
      for j in range(i+1, len(x)):
        x[j] = max(0, x[j-1]-1)
      break
    elif cur < x[i+1] - 1:
      x[i] += 1
      for j in range(i+1, len(x)):
        x[j] = max(0, x[j-1]-1)
      break

  for i in range(len(x)):
    x[i] = str(x[i])

  return int(''.join(x))

k = int(input())

k-=1

x=1

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

print(x)

Submission status: Wrong Answer

Solution code:
K = int(input())

t = -1
for i in range(1,10**6):
    for j in range(len(str(i)) - 1):
        if abs(int(str(i)[j]) - int(str(i)[j+1])) > 1:
            break
    else:
        t += 1
        #print(i,t)
    if t+1 == K:
        break
print(i)

Submission status: Wrong Answer

Solution code:
from collections import deque

k = int(input())
limit = 10 ** 5
ans = deque([str(i) for i in range(1, 10)])
que = deque(ans)
while que:
    num = que.popleft()
    if num[-1] == 0:
        que.append(num + '0')
        que.append(num + '1')
        ans.append(num + '0')
        ans.append(num + '1')
    elif num[-1] in [str(i) for i in range(1, 9)]:
        n_last = int(num[-1])
        que.append(num + str(n_last-1))
        que.append(num + str(n_last))
        que.append(num + str(n_last + 1))
        ans.append(num + str(n_last - 1))
        ans.append(num + str(n_last))
        ans.append(num + str(n_last + 1))
    else:
        que.append(num + '8')
        que.append(num + '9')
        ans.append(num + '8')
        ans.append(num + '9')
    if len(ans) >= k:
        print(ans[k-1])
        exit()

Submission status: Wrong Answer

Solution code:
a=int(input())

list=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23]
i=1
while(a<=15):
    print(list[a-1])
    break

Submission status: Wrong Answer

Solution code:
k=input()

ln=[1,2,3,4,5,6,7,8,9]
old=0
new=9
while len(ln)<100001:
    for i in xrange(old, new):
        if ln[i]%10!=9:
            ln.append(ln[i]*10+ln[i]%10-1)
            ln.append(ln[i]*10+ln[i]%10)
            ln.append(ln[i]*10+ln[i]%10+1)
        else:
            ln.append(ln[i]*10+ln[i]%10-1)
            ln.append(ln[i]*10+ln[i]%10)
    old=new
    new=len(ln)

ln.sort()
print ln[k-1]

Submission status: Wrong Answer

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

for i in range(10 ** 5):
  char = str(i + 1)
  count = 0
  for j in range(len(char) - 1):
    if abs(int(char[j]) - int(char[j + 1])) <= 1:
      count += 1
  if count == len(char) - 1:
    k -= 1
    if k == 0:
      print(i + 1)
      sys.exit()

Submission status: Wrong Answer

Solution code:
k=int(input())
if k//10==0:
    print(k)
    exit()

cnt=0
x=9
while k>=cnt:
    x+=1
    l=str(x)
    a = [int(c) for c in l]
    for i in range(len(a)-1):
        if a[i]-a[i+1]==1 or a[i]-a[i+1]==-1:
            cnt+=1

    if k-11==cnt:
        print(x)
        exit()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
count = 0


def solve(K: int):

    def cDfs(prev, prevDigit, remainDigit):
        global count
        if remainDigit == 0:
            count += 1
            if count == K:
                print(prev)
                exit()
            return
        else:
            if prevDigit == 0:
                cDfs(prev*10, prevDigit, remainDigit-1)
                cDfs(prev*10+1, 1, remainDigit-1)
            elif prevDigit == 9:
                cDfs(prev*10+9, prevDigit, remainDigit-1)
                cDfs(prev*10+8, 8, remainDigit-1)
            else:
                a = (prevDigit+1) % 10
                b = (prevDigit-1) % 10
                MIN = min(a, b)
                MAX = max(a, b)
                cDfs(prev*10+MIN, MIN, remainDigit-1)
                cDfs(prev*10+prevDigit, prevDigit, remainDigit-1)
                cDfs(prev*10+MAX, MAX, remainDigit-1)
    for i in range(0, 100):
        for j in range(1, 10):
            cDfs(j, j, i)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

K = int(input())

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

for i in range(1, 100001):
    one = i%10
    if one == 0:
        arr.append(i*10 + 0)
        arr.append(i*10 + 1)
    elif one == 9:
        arr.append(i*10 + 8)
        arr.append(i*10 + 9)
    else:
        arr.append(i*10 + one - 1)
        arr.append(i*10 + one)
        arr.append(i*10 + one + 1)

arr.sort()

print(arr[K-1])

Submission status: Wrong Answer

Solution code:
n=int(input())
def runrun_check(num):
    num=list(map(int,str(num)))
    for i in range(len(num)-1):
        if abs(num[-(i+2)]-num[-(i+1)])>=2:
            return i+1
    return 0
ans=0
for i in range(n):
    ans+=1
    tmp=runrun_check(ans)
    while tmp:
        ans+=10**(tmp-1)
        tmp=runrun_check(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
k = int(input()) - 1
if len(str(k)) == 1:
    print(k + 1)
else:
    jjj = 0
    ans = [0]

    num = 0
    dps = []
    dp = [1] * 10
    dp[0] = 0

    flag = False
    for i in range(len(dp)):
        num += dp[i]
        if num > k:
            flag = True
            break

    dp[0] = 1
    dps.append(dp)

    flag = False
    while True:
        dp = [0] * 10
        dp[0] = 0
        for i in range(1, 9):
            dp[i] = sum(dps[-1][i - 1 : i + 2])
        dp[9] = dps[-1][8] + dps[-1][9]


        for i in range(len(dp)):
            num += dp[i]
            if num > k:
                flag = True
            if flag:
                num -= dp[i]
                break
        if flag:
            break
        dp[0] = dps[-1][0] + dps[-1][1]
        dps.append(dp)

    ans = [i]
    k = k - num
    jjj += 1

    try:
        while True:
            num = 0
            ii = i
            for i in range(ii - 1, ii + 2):
            #     print(i)
                if num + dps[-1][i]> k:
                    break
                else:
                    num += dps[-1][i]

            ans.append(i)
            k -= num
            dps = dps[:-1]
    except:
        print("".join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
K = int(input())
s = '0'
cnt = 0
while cnt<K:
  cnt += 1
  ns = ''
  j = -1
  for i in range(len(s)-1,0,-1):
    if int(s[i])+1<=int(s[i-1])+1 and int(s[i])+1<10:
      j = i
      break
  else:
    if s[0]<'9':
      j = 0
  if j!=-1:
    for i in range(len(s)):
      if i==j:
        x = str(int(s[i])+1)
      elif i<j:
        x = s[i]
      elif i==j+1:
        x = str(int(s[j]))
      else:
        x = str(max(int(s[j])-1,0))
      ns += x
  else:
    ns = '1'+'0'*len(s)
  s = ns
#  print(s,)
print(s)

Submission status: Wrong Answer

Solution code:
import itertools
k = int(input())
l = [1,2,3,4,5,6,7,8,9]
for i in range(2,11):
    for j in range(1,10):
        if j == 9:
            li = [j-1,j]
        else:
            li = [j-1,j,j+1]
        for m in list(itertools.product(li, repeat=(i-1))):
            l.append(int(str(j)+''.join(map(str,m))))
print(l[k-1])

Submission status: Wrong Answer

Solution code:
def d1(x):
    y = x % 10
    if y == 0:
        return [0, 1]
    elif y == 9:
        return [8, 9]
    else:
        return [y-1, y, y+1]


K = int(input())

runrun = []
N = 0
digit = 0
while N < K:
    d_i = []
    if digit == 0:
        for i in range(1, 10):
            d_i.append(i)
        N += len(d_i)
        runrun.append(d_i)
        digit += 1
    else:
        tmp = runrun[digit-1]
        for x in tmp:
            for y in d1(x):
                d_i.append(10*x+y)
        N += len(d_i)
        runrun.append(d_i)
        digit += 1

print(runrun[-1][K-N+1])

Submission status: Wrong Answer

Solution code:
k = int(input())

dp = [[[] for j in range(11)] for i in range(11)]

for i in range(10):
    dp[1][i].append(i)

for i in range(11):
    dp[i][0].append(0)


if k<=9:
    print(k)
    exit()

k-=9

for i in range(2, 11):
    for j in range(1, 10):
        for x in dp[i-1][j-1]:
            dp[i][j].append(j*10**(i-1)+x)
            k-=1
            if k==0:
                print(dp[i][j][-1])
                exit()
        for x in dp[i - 1][j]:
            dp[i][j].append(j * 10 ** (i-1) + x)
            k-=1
            if k==0:
                print(dp[i][j][-1])
                exit()
        for x in dp[i - 1][j + 1]:
            dp[i][j].append(j * 10 ** (i-1) + x)
            k-=1
            if k==0:
                print(dp[i][j][-1])
                exit()

Submission status: Wrong Answer

Solution code:
def main():
    K = int(input())
    used = [1,2,3,4,5,6,7,8,9]
    ans = used
    k = 9
    now = 0
    add = [-1,0,1]
    while True:
        if k >= K :
            break
        else:
            keep = []
            for i in used:
                if (i % 10 == 0 ) :
                    keep.append(i * 10 + 0)
                    keep.append(i * 10 + 1)
                    continue
                if (i % 10 == 9):
                    keep.append(i * 10 + 9)
                    keep.append(i * 10 + 8)
                    continue
                p = (i % 10)
                for j in range(3):
                    keep.append(i * 10 + p + add[j])
            k += len(keep)
            ans += keep
            used = keep
    print(ans[K-1])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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


K = int(input())

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

for i in range(100000):
	for j in range(3):
		if ans[i]%10 == 0 and j ==0:
			continue
		elif ans[i]%10 == 9 and j ==2:
			continue
		ans.append(ans[i]*10+j-1+ans[i]%10)

print(ans[K+1])

Submission status: Wrong Answer

Solution code:
mod = 10**9+7
import sys
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations
from itertools import accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil,floor
from copy import deepcopy
from heapq import heappop,heappush,heapify
import heapq


sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

# リストの要素を改行を挟んで表示する
p2D = lambda x: print(*x, sep="\n")
# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

# 入力全てを整数に変換したものの配列を受け取る
# def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def LI(): return list(map(lambda x:int(x), sys.stdin.readline().split()))
def HI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))

K = II()
# tmp = n
# p = 1
# keta = 0
# while(tmp>=0):
# 	tmp -= tmp-p
# 	p *= 3
# 	keta+=1
# keta-=1

def lun(num):
	s = str(num)
	for i in range(len(s)-1):
		# print(i)
		if abs(int(s[i])-(int(s[i+1])))>1:
			return False
	return True
num = 1
count = 0
while(1):
	if lun(num):
		count+=1
	if count==K:
		print(num)
		break
	num+=1
print(num)

Submission status: Wrong Answer

Solution code:
k = int(input())

count = 0
number = 0
while count < k : 
    word = str(number)
    flag = 1
    for i in range(len(word)-1) : 
        if abs(int(word[i]) - int(word[i+1])) > 1 : 
            flag = 0
            break
    if flag == 1 : 
        count += 1
    number += 1
print(number)

Submission status: Wrong Answer

Solution code:
K = int(input())
count =0 
j =0 
while True:
    j+=1
    t = [int(i) for i in list(str(j))]
    a = len(t)
    for i,v in enumerate(t):
        if i < a-1:
            if abs(t[i] - t[i+1]) > 1:
                break
    count += 1
    if count ==K:
        print(j)
        exit()

Submission status: Wrong Answer

Solution code:
k = int(input())
dp = [[0]*10 for i in range(12)]  # dp[i][j]: i桁で先頭がj

for i in range(10):
    dp[1][i] = 1

for i in range(1,10):
    for j in range(10):
        dp[i+1][j] += dp[i][j]
        if j<9:
            dp[i+1][j] += dp[i][j+1]
        if j>0:
            dp[i+1][j] += dp[i][j-1]

ans = 0
for i in range(11):
    for j in range(1,10):
        if k > dp[i][j]:
            k -= dp[i][j]
        else:
            ni = i-1
            nj = j
            ans = j
            break
    if ans > 0:
        break

while ni > 0:
    for j in range(nj-1,nj+2):
        if k > dp[ni][j]:
            k -= dp[ni][j]
        else:
            ans = ans*10+j
            nj = j
            break
    ni -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
def countBits(number): 
    return int((math.log(number)/math.log(2)) + 1); 
# t=int(input(""))
t=1
for _ in range(t):
    k=int(input(""))
    A=[1,2,3,4,5,6,7,8,9]
    i=0
    while(len(A)<=k):
        A.append(A[i]*10+(A[i]-1)%10)
        A.append(A[i]*10+(A[i])%10)
        A.append(A[i]*10+(A[i]+1)%10)
        i+=1
    # print(A)
    print(A[k-1])

Submission status: Wrong Answer

Solution code:
def main():

    K = int(input())
    cur = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    if K <= len(cur):
        return cur[K-1]
    K -= 9
    while True:
        temp = []
        for v in cur:
            if v % 10 == 0:
                temp.append(v*10 + v % 10)
                temp.append(v*10 + 1)
            elif v % 10 == 9:
                temp.append(v*10 + v % 10)
                temp.append(v*10 + 8)
            else:
                temp.append(v * 10 + v%10 - 1)
                temp.append(v*10 + v % 10)
                temp.append(v * 10 + v%10 + 1)
        # print(temp)
        if len(temp) >= K:
            return temp[K-1]
        cur = temp
        K -= len(temp)
    return -1


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

Submission status: Wrong Answer

Solution code:
import sys
K = int(sys.stdin.readline())

Submission status: Wrong Answer

Solution code:
from collections import deque
k=int(input())
l=deque([i+1 for i in range(9)])
cnt=9
if k<=cnt:print(l[k-1])
else:
    while cnt<k:
        v=l.popleft()
        if v%10==0:l.append(v*10);l.append(v*10+1);cnt+=2
        elif v%10==9:l.append(v*10+9);l.append(v*10+8);cnt+=2
        else:
            rem=v%10
            l.append(v*10+rem-1)
            l.append(v*10+rem)
            l.append(v*10+rem+1)
            cnt+=3
    print(l[k-cnt-1])

Submission status: Time Limit Exceeded

Solution code:
def update_queue(queue):
    out = queue.pop(0)
    mod10 = out % 10
    if mod10 != 0:
        queue.append(10 * out + mod10 - 1)
    queue.append(10 * out + mod10)
    if mod10 != 9:
        queue.append(10 * out + mod10 + 1)

    return out, queue

N = int(input())
Q = [1,2,3,4,5,6,7,8,9]

for _ in range(N):
    out, Q = update_queue(Q)

print(out)

Submission status: Time Limit Exceeded

Solution code:
def make(Lun):
    Lunstr = str(Lun)
    Lu = []
    if Lunstr[-1] != '9' and Lunstr[-1] != '0':
        for i in range(-1,2):
            New = int(Lunstr + str(int(Lunstr[-1]) + i))
            Lu.append(New)
    elif Lunstr[-1] == '9':
        for i in range(-1,1):
            New = int(Lunstr + str(int(Lunstr[-1]) + i))
            Lu.append(New)
    else:
        for i in range(0,2):
            New = int(Lunstr + str(int(Lunstr[-1]) + i))
            Lu.append(New)
    return Lu
LunLun = [i for i in range(1,10)]
k = 0
i = 10
K = int(input())
sig = 0
for _ in range(100000000):
    NewLun = LunLun[k:i]
    for j in range(len(NewLun)):
        LunLun = LunLun + make(NewLun[j])
        if len(LunLun) >= K:
            sig = -1
            break
    k = i-1
    i = len(LunLun) + 1
    if sig == -1:
        break
print(LunLun[K-1])

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

def is_lun(n):
    d, m = divmod(n, 10)
    last = m
    while d:
        n = d
        d, m = divmod(n, 10)
        if abs(last - m) > 1:
            return False
        last = m
    return True

from sys import exit
ans = 1
cnt = 0
while 1:
    if is_lun(ans):
        cnt += 1
    if cnt == k:
        print(ans)
        exit()
    ans += 1

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

ans=0

for num in range(1,10**10):
    num_str=str(num)
    num_str=num_str[::-1]
    hantei=True

    if len(num_str)>1:
        for i in range(len(num_str)-1):
            if abs(int(num_str[i])-int(num_str[i+1]))>1:
                hantei=False
                break
    if hantei:
        ans+=1

        if k==ans:
            print(num)
            exit()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

count = 0
check = 1

def lun(n):
    if len(str(n)) ==1:
        return True
    else:
        m = str(check)
        keta = len(m)
        for i in range(1, keta):
            if int(m[i]) != int(m[i-1]) and int(m[i]) != int(m[i-1]) +1 and int(m[i]) != int(m[i-1]) -1:
                return False
        return True

while count < k:
    if lun(check):
        count +=1
    check += 1
print(check-1)

Submission status: Time Limit Exceeded

Solution code:
def runrun(a):
    s = str(a)
    n = len(s)
    for i in range(n-1):
        if abs(int(s[i])-int(s[i+1]))>1:
            return False
    return True

x = int(input())
tmp = [0]
cnt = 0
i = 0
while cnt<x:
    i += 1
    if runrun(i):
        cnt += 1
        tmp.append(i)
#print(tmp)
print(i)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
for i in range(13):
    if K == i:
        print(i)
        exit()

i = 12
order = 12
while(True):
    flag = True
    for j in range(len(str(i))-1):
        diff = abs(int(str(i)[j]) - int(str(i)[j+1]))
        if diff > 1:
            i += 1
            flag = False
            continue
    if order == K and flag:
        print(i)
        break
    if flag:
        i += 1
        order += 1

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
number=[]
for i in range(3234566668):
    k=str(i)
    if all([abs(int(k[j])-int(k[j-1]))<=1 for j in range(1,len(k))]):
        number.append(k)
print(number[K])

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
ans=set()
for i in range(1,10):
    ans.add(i)
def saiki(A):
    genzai_saigo=int(A[-1])
    ketasu=len(A)
    if ketasu>0:
        B="".join(A)
        ans.add(eval(B))
    if ketasu==10:
        return
    for i in [genzai_saigo-1,genzai_saigo,genzai_saigo+1]:
        if i < 0 or i>9:
            continue
        A.append(str(i))
        saiki(A)
        A.pop()
for i in range(1,10):
    saiki([str(i)])
kotae=list(ans)
kotae.sort()
print(kotae[K-1])