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())
A=[0]*10
indicator=[0]*10
for i in range(0,K):
    for j in range(0,10):
        if A[j]==9:
            indicator[j]=1
    for j in range(0,10):
        if indicator[9-j]==1:
            continue
        break
    A[9-j]=A[9-j]+1
    for k in range(9-j,9):
        if A[k]==0:
            A[k+1]=0
        else:
            A[k+1]=A[k]-1
    for k in range(0,9):
        indicator[k+1]=A[k+1]-A[k]
        if A[k+1]==1 and A[k]==0:
            indicator[k+1]=0
print(A)

Submission status: Wrong Answer

Solution code:
K = int(input())

answer = [0]

for k in range(K):
  minvalue = min(answer)
  if minvalue == 9:
    for i in range(len(answer)):
      answer[i] = 0
    answer.append(1)
  else:
    target = answer.index(minvalue)
    answer[target] += 1
    if target != 0:
      for i in range(len(answer) - target):
        iindex = target - i - 1
        if 1 <= iindex + 1 <= len(answer) - 1:
          answer[iindex] = max(0, answer[iindex + 1] - 1)

answer.reverse()
print(''.join(map(str, answer)))

Submission status: Wrong Answer

Solution code:
# import sys
# import math #sqrt
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# import itertools
# import collections # deque
# from operator import itemgetter
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def dfs(pos,size):
    global a,ans
    if pos==len(a):
        res = 0
        for i in range(len(a)):
            res += a[i]*(10**i)
        ans.add(res)
        return
    if pos!=0:
        for i in range(max(0,a[pos-1]-1),a[pos-1]+2):
            a[pos] = i
            dfs(pos+1,size)
    else:
        for i in range(10):
            a[pos] = i
            dfs(pos+1,size)

def main():
    global ans,a
    k = int(input())
    ans = set()
    a = [0]
    while (len(ans)<=k):
        dfs(0,len(a))
        a.append(0)
    ans = list(ans)
    ans.sort()
    print(ans[k])
    return

if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

while 1:
    if 3**keta * 9 > k:
        break
    keta += 1

kk = 10 * keta
count = 0 if keta == 0 else 3**(keta-1) * 9
if kk == 0:
    print(k)
else:
    while count < k:
        for i in range(len(str(kk))-1):
            if abs(int(str(kk)[i])-int(str(kk)[i+1])) > 1:
                break
            if i == len(str(kk))-2:
                count += 1
        kk += 1
    print(kk-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
def ch(num):
    if num==0:
        return [0,1]
    if num==1:
        return [0,1,2]
    if num==2:
        return [1,2,3]
    if num==3:
        return [2,3,4]
    if num==4:
        return [3,4,5]
    if num==5:
        return [4,5,6]
    if num==6:
        return [5,6,7]
    if num==7:
        return [6,7,8]
    if num==8:
        return [7,8,9]
    if num==9:
        return [8,9]
#n=100000
cnt=35
from collections import deque
b=deque([ 10, 11, 12, 21, 22, 23, 32, 33, 34, 43, 44, 45, 54, 55, 56, 65, 66, 67, 76, 77, 78, 87, 88, 89, 98, 99])
li=[ 10, 11, 12, 21, 22, 23, 32, 33, 34, 43, 44, 45, 54, 55, 56, 65, 66, 67, 76, 77, 78, 87, 88, 89, 98, 99]
while len(b)>0:
  c=b.popleft()
  #print(c)
  d=int(str(c)[-1])
  for i in ch(d):
    b.append(int(str(c)+str(i)))
    li.append(int(str(c)+str(i)))
    #print(b[-1])
    cnt+=1
    if b[-1]==999:print(cnt)
  if cnt>=n:break
if n<9:
  print(n)
elif 10<n<36:
  print([ 10, 11, 12, 21, 22, 23, 32, 33, 34, 43, 44, 45, 54, 55, 56, 65, 66, 67, 76, 77, 78, 87, 88, 89, 98, 99][n-10])
else:
  print(b[-1])

Submission status: Wrong Answer

Solution code:
def main():
    K = str(input())
    K_int = int(K)
    K_len = len(K)
    frag_runrun = 0
    count_runrun = 12
    for i_cycle in range(1, K_int * 100) :
        #print("count_runrun=%s" % count_runrun)
        if K_int <= 12 :
            print(K_int)
            break
        elif K_int > 12 and count_runrun != K_int :
            i_cycle = i_cycle + 12
            str_i_cycle = str(i_cycle)
            len_i_cycle = len(str_i_cycle)
            #print("i_cycle=%s" % i_cycle)
            #print("len_i_cycle=%s" % len_i_cycle)
            for j_cycle in range(0, len_i_cycle-1) :
                #print(int(str_i_cycle[j_cycle+1]))
                if abs(int(str_i_cycle[j_cycle+1]) - int(str_i_cycle[j_cycle])) <= 1 :
                    frag_runrun = 1
                else :
                    frag_runrun = 0
                    break
            if frag_runrun == 1 :
                count_runrun = count_runrun + 1
                frag_runrun = 0
            else :
                pass
        else :
            print(i_cycle + 11)
            break


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
MOD = 1000000007

k = int(input())
number = 9

ans = 0
for i in range(10,10**6):
    check = 'OK'
    l = len(str(i))
    keta = list(str(i))
    for j in range(l-1):
        if abs(int(keta[j]) - int(keta[j+1])) <= 1:
            pass
        else:
            check = 'NG'
    if check == 'OK':
        number += 1
        if number == k:
            ans = i%MOD
            break
if k <= 9:
    print(k)
else:
    print(ans%MOD)

Submission status: Wrong Answer

Solution code:

def resolve():
    import sys
    input = sys.stdin.readline
    k = int(input().rstrip())

    if k <= 9:
        # print(k)
        sys.exit()

    def judge(number_list, index, total):
        if index == len(number_list) - 2:  # 最後から2番目の桁
            num = number_list[index]
            add_num = 2 if num in (0, 9) else 3
            if (total + add_num) < k:
                total += add_num
                return total
            else:
                if num == 0:
                    right_nums = [num, num + 1]
                elif num == 9:
                    right_nums = [num-1,num]
                else:
                    right_nums = [num-1,num,num+1]
                number_list[-1] = right_nums[k-total-1]
                # print("".join(number_list))
                print(*number_list,sep="")
                sys.exit()
        else:  # 最後から２番目の桁じゃない
            num = number_list[index]
            if num == 0:
                right_nums = [num, num + 1]
            elif num == 9:
                right_nums = [num - 1, num]
            else:
                right_nums = [num - 1, num, num + 1]

            for right_num in right_nums:
                number_list[index+1] = right_num
                total = judge(number_list, index+1, total)
            return total

    total = 9
    num_list = [9]
    while True:
        num_list = [0 for _ in range(len(num_list)+1)]
        for left in [1,2,3,4,5,6,7,8,9]:
            num_list[0] = left
            # print(num_list, 0, total)
            total = judge(num_list, 0, total)




if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
k = int(input())
n = 1
cnt = 0
flg = 0
while True:
  if flg == 1:
    n += 1
  flg = 0
  strn = str(n)
  if len(strn) == 1:
    cnt += 1
    n += 1
  else:
    for s in range(len(strn)):
      if s == len(strn) - 1:
        cnt += 1
        flg = 1
      else:
        if abs(int(strn[s]) - int(strn[s+1])) > 1:
          if int(strn[s]) - int(strn[s+1]) > 1:
            new = ''
            for ss in range(len(strn)):
              if s+1 == ss:
                new += str(int(strn[s]) - 1)
              else:
                new += strn[ss]
            n = int(new)
          else:
            new = ''
            for ss in range(len(strn)):
              if s == ss:
                new += str(int(strn[s]) + 1)
              elif s+1 == ss:
                new += '0'
              else:
                new += strn[ss]
            n = int(new)
          break
          
    
  if cnt == k:
    print(n)
    break

Submission status: Wrong Answer

Solution code:
N = int(input())
print(N)

num = (N-9) // 3 
num_2 = (N-9) % 3

if N < 9:
  print(N)
else:
  (num + 1) * 10 + num_2

Submission status: Wrong Answer

Solution code:
k = int(input())
i = 0
a = []
while len(a) <= k:
    if len(str(i)) == 1:
        a.append(i+1)
    else:
        flg = True
        for j in range(len(str(i))):
            if j != len(str(i))-1:
                t = abs(int(str(i)[j]) - int(str(i)[j+1]))
                if t > 1:
                    flg = False
        if flg == True:
            a.append(i)
    i = i+1

print(a[k])

Submission status: Wrong Answer

Solution code:
k = int(input())
precnt = 35
cnt = 35
keta = 3
sum = 0
if k <= 9:
  print(k)
if 9 < k <= 35:
  k -= 9
  a = k / 3
  b = k % 3
  if b == 0:
    print(a*10 + a+1)
  elif b == 1:
    print((a+1)*10 + a-1)
  else:
    print((a+1)*10 + a)
else:
  for i in range(3,):
    cnt += 77*(3**(i-3))
    if precnt < k <= cnt:
      keta = i
      break
    precnt = cnt
  k -= precnt
  a = k / (3**(keta-1))
  b = k % (3**(keta-1))
  if b == 0:
    for j in reversed(range(keta)):
      sum += a*(10**(j))
      a += 1
      print(sum)

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)
  i = 0
  if i+1 < nowlen:
    if abs(int(STR[i]) - int(STR[i+1])) > 1:
      return False
  if i+2 < nowlen:
    if abs(int(STR[i+1]) - int(STR[i+2])) > 1:
      return False
  if i+3 < nowlen:
    if abs(int(STR[i+2]) - int(STR[i+3])) > 1:
      return False
  if i+4 < nowlen:
    if abs(int(STR[i+3]) - int(STR[i+4])) > 1:
      return False
  if i+5 < nowlen:
    if abs(int(STR[i+4]) - int(STR[i+5])) > 1:
      return False
  if i+6 < nowlen:
    if abs(int(STR[i+5]) - int(STR[i+6])) > 1:
      return False
  if i+7 < nowlen:
    if abs(int(STR[i+6]) - int(STR[i+7])) > 1:
      return False
  if i+8 < nowlen:
    if abs(int(STR[i+7]) - int(STR[i+8])) > 1:
      return False
  if i+9 < nowlen:
    if abs(int(STR[i+8]) - int(STR[i+9])) > 1:
      return False
  if i+10 < nowlen:
    if abs(int(STR[i+9]) - int(STR[i+10])) > 1:
      return False
  return True
  
def main():
  k = int(input())
  if 1 <= k <= 9:
    print(k)
    exit()
  else:
    idx = 12
    now = k
    while True:
      if Lun(now):
        idx += 1
        if idx == k:
          print(now)
          exit()
        now += 1
      else:
        now += 1
      
      
      
      
    """PO = (k-9)//3 - 1
    idx = 9 + 3*PO
    now = 10 * (PO+1)
    while True:
      if idx == k:
        print(now)
        exit()
      
      #----

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

Submission status: Wrong Answer

Solution code:
K = int(input())

def runrunConfirm(num):
    flag=True
    str_num=str(num)
    strlen=len(str_num)
    if strlen==1:
        return True
    for i in range(strlen-1):
        if i==0:
            tmp=int(str_num[i])-int(str_num[i+1])
            if abs(tmp)>1:
                flag=False
                break
        # elif i==len(str_num)-1:
        #     tmp=int(str_num[i-1])-int(str_num[i])
        #     if abs(tmp)>1:
        #         flag=False
        #         break
        # else:
        #     tmp=int(str_num[i])-int(str_num[i+1])
        #     if abs(tmp)>1:
        #         flag=False
        #         break
            # tmp=int(str_num[i-1])-int(str_num[i])
            # if abs(tmp)>1:
            #     flag=False
            #     break
    return flag

number=1
runrunlist=0
while True:
    if runrunConfirm(number):
        runrunlist+=1
    if runrunlist==K:
        print(number)
        exit()
    number+=1

Submission status: Wrong Answer

Solution code:
s=int(input())
if s <= 12:
  print(s)
else:
  count = s - 12
  num = 12
  while count > 0:
    num += 1
    numlist = [int(x) for x in list(str(num))]
    if numlist[-1] == numlist[-2]:
      count -= 1
    elif abs(numlist[-1] - numlist[-2]) == 1:
      count -= 1
  print(num)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from heapq import heapify, heappush
K = int(input())
queue = [str(i) for i in range(1, 10)]
# print(queue)
L = []
# L = heapify(L)
# print(type(L))
# exit()
while queue:
    v = queue.pop(0)
    # L.push(int(v))
    heappush(L, int(v))
    if v[-1] == "0":
        # print("v =", v)
        queue.append(v + v[-1])
        queue.append(v+"1")
        
    elif v[-1] == "9":
        # print("9", v)
        queue.append(v + "8")
        queue.append(v + v[-1])
    else:
        # print("else", v)
        t = int(v[-1])
        queue.append(v+str(t-1))
        queue.append(v+str(t+1))
        queue.append(v + v[-1])
    if len(L) >= K + 100:
        break
L.sort()
# print()
# L = heapify(L)
# print(type(L))
print(L[K-1])
# print()
# print(L[-39:])
# print(L[K-1])

Submission status: Wrong Answer

Solution code:
num = int(input())
count = 0
def check(x):
    if(x < 10):
        return True
    x = str(x)
    for i in range(len(x)-1):
        if( int(x[i]) - int(x[i + 1]) == 0):
            return True
        elif( int(x[i]) - int(x[i + 1]) == 1 ):
            return True
        elif( int(x[i]) - int(x[i + 1]) == -1 ):
            return True
    return False
i = 0    
while(True):
    i = i + 1
    if(check(i)):
        count = count + 1 
        if(count == num ):
            print(i)
            exit()

Submission status: Wrong Answer

Solution code:
import numpy as np

K = int(input())

kazu = 1
i = 1
while kazu < K:
    if i < 10:
        i += 1
        kazu += 1
    else:
        suchi_list = [int(x) for x in list(str(i))]
        diff = np.diff(suchi_list)
        if max(abs(diff)) <= 1:
            kazu += 1
        i += 1
        

print(i)

Submission status: Wrong Answer

Solution code:
k=int(input())
a=[1,2,3,4,5,6,7,8,9]
n=10
m=9
t=False
while(m<k):
    t=False
    for i in range(len(str(n))-1):
        if abs(int(str(n)[i])-int(str(n)[i+1]))<=1:
            t=True
        else:
            t=False
            break
    if t:
        a=n
        m+=1
    n+=1
print(a)

Submission status: Wrong Answer

Solution code:
k = int(input())

def get_below(a):
    s = str(a)
    if len(s) == 1:
        return a
    else:
        ret = 0
        for i in range(len(s)):
            ret += sum(nums[i][1:])

        for i in range(1, int(s[0])):
            ret += nums[len(s)][i]

        def dfs(ss):
            # start: fixed
            if len(ss) == 1:
                return 1
            if int(ss[0]) > int(ss[1]) + 1:
                return 0
            elif int(ss[0]) == int(ss[1]) + 1:
                return dfs(ss[1:])
            elif int(ss[0]) == int(ss[1]):
                ret = nums[len(ss) - 1][int(ss[1]) - 1]
                return ret + dfs(ss[1:])
            elif int(ss[0]) + 1 == int(ss[1]):
                ret = nums[len(ss) - 1][int(ss[1]) - 1] + nums[len(ss) - 1][int(ss[1]) - 2]
                return ret + dfs(ss[1:])
            else:
                return nums[len(ss)][int(ss[0])]

        return ret + dfs(str(a))

if k <= 10:
    print(k)
else:
    nums = [[0] * 10 for _ in range(11)]
    nums[1] = [1] * 10

    for i in range(11):
        for j in range(10):
            if j != 0:
                nums[i][j] += nums[i-1][j-1]
            if j != 9:
                nums[i][j] += nums[i-1][j+1]
            nums[i][j] += nums[i-1][j]

    lo = 0
    hi = 10 ** 10
    while hi - lo > 1:
        mid = (lo + hi) // 2
        if get_below(mid) - k >= 0:
            hi = mid
        else:
            lo = mid

    print(hi)

Submission status: Wrong Answer

Solution code:
k=int(input())
def count(i,num):
    if i==1:
        return 1
    c=0
    if num!=0:
        c+=count(i-1,num-1)
    c+=count(i-1,num)
    if num!=9:
        c+=count(i-1,num+1)
    return c

def answer(i,num,range,ans):
    if i==1:
        if num==0:
            return ans*10+range-1
        else:
            return ans*10+range+num-2
    if num!=0:
        c=count(i-1,num-1)
        if c>=range:
            return answer(i-1,num-1,range,ans*10+num-1)
        range-=c
    c=count(i-1,num)
    if c>=range:
        return answer(i-1,num,range,ans*10+num)
    range-=c
    if num!=9:
        c=count(i-1,num+1)
        if c>=range:
            return answer(i-1,num+1,range,ans*10+num+1)
    return 0

size=9
num=1
i=2
while True:
    s=count(i,num)
    if s+size>=k:
        break
    size+=s
    num+=1
    if num==10:
        num=1
        i+=1
ans=0
if k<=9:
    ans=k
else:
    ans=answer(i-1,num,k-size,num)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
K=100000

n=np.zeros((10,11),dtype=int)
for i in range(9):
	n[i+1,1]=1
	n[i+1,2]=3
n[9,2]=2

for i in range(3,11):
	n[1,i]=n[2,i-1]+np.sum(n[1,:])
	n[2,i]=n[1,i-1]+n[2,i-1]+n[3,i-1]
	n[3,i]=n[4,i-1]+n[2,i-1]+n[3,i-1]
	n[4,i]=n[4,i-1]+n[5,i-1]+n[3,i-1]
	n[5,i]=n[4,i-1]+n[5,i-1]+n[6,i-1]
	n[6,i]=n[5,i-1]+n[6,i-1]+n[7,i-1]
	n[7,i]=n[7,i-1]+n[8,i-1]+n[6,i-1]
	n[8,i]=n[7,i-1]+n[8,i-1]+n[9,i-1]
	n[9,i]=n[8,i-1]+n[9,i-1]

i=1
j=1

def ninecheck(i,j,K,ans):
	for k in range(2):
		K-=n[i-1+k,j]
		if K<=0:
			K+=n[i-1+k,j]
			ans+=(i-1+k)*(10**(j-1))
			if j==1:
				a=ans
				return a
			j-=1
			i=i-1+k
			if i==1:
				a=onecheck(i,j,K,ans)
				return a
			elif i==9:
				a=ninecheck(i,j,K,ans)
				return a
			else:
				a=normalcheck(i,j,K,ans)
				return a

def onecheck(i,j,K,ans):
	for k in range(1,j+1):
		K-=n[1,k]
		if K<=0:
			K+=n[1,k]
			ans+=10**(k-1)
			j=k
			if j==1:
				a=ans
				return a
			j-=1
			a=onecheck(i,j,K,ans)
			return a
	i=2
	ans+=i*(10**(j-1))
	j-=1
	a=normalcheck(i,j,K,ans)
	return a

def normalcheck(i,j,K,ans):
	for k in range(3):
		K-=n[i-1+k,j]
		if K<=0:
			K+=n[i-1+k,j]
			ans+=(i-1+k)*(10**(j-1))
			if j==1:
				a=ans
				return a
			j-=1
			i=i-1+k
			if i==1:
				a=onecheck(i,j,K,ans)
				return a
			elif i==9:
				a=ninecheck(i,j,K,ans)
				return a
			else:
				a=normalcheck(i,j,K,ans)
				return a



ans=0
while True:
	K-=n[i,j]
	if K<=0:
		ans+=i*(10**(j-1))
		K+=n[i,j]
		if j==1:
			b=ans
			break
		j-=1
		if i==1:
			b=onecheck(i,j,K,ans)
			break
		elif i==9:
			b=ninecheck(i,j,K,ans)
			break
		else:
			b=normalcheck(i,j,K,ans)
			break
	if i==9:
		i=1
		j+=1
	else:
		i+=1
		continue




print(b)

Submission status: Wrong Answer

Solution code:
k = int(input())

runrun = [1,2,3,4,5,6,7,8,9]
for i in range(10, 100000):
    si = str(i)
    lsi = len(si)
    for i in range(lsi-1):
        if abs(int(si[i])- int(si[i+1]))<=1:
            runrun.append(int(si))

print(runrun[k-1])

Submission status: Wrong Answer

Solution code:
def dp(i, j, memo):
    key = "{}.{}".format(i, j)

    if i == 1:
        memo[key] = 1
        return memo[key]

    if key in memo:
        return memo[key]

    if j == 0:
        memo[key] = dp(i-1, j, memo) + dp(i-1, j+1, memo)
        return memo[key]

    if j == 9:
        memo[key] = dp(i-1, j-1, memo) + dp(i-1, j, memo)
        return memo[key]

    memo[key] = dp(i-1, j-1, memo) + dp(i-1, j, memo) + dp(i-1, j+1, memo)
    return memo[key]


k = int(input())
memo = {"1.0": 0}

num = 0

i = 1
j = 0

while(num < k):
    j += 1
    j %= 10
    if j == 0:
        i += 1
    else:
        num += dp(i, j, memo)

p = k - num + dp(i, j, memo)
ans = [j]
print(i, j)
for l in range(1, i):
    n = 0
    x = max(-1, ans[-1] - 2)
    while n < p and x < 10:
        x += 1
        n += dp(i-l, x, memo)
    ans.append(x)
    p = p - n + dp(i-l, x, memo)

print("".join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
import numpy as np
K = int(input())
count = 9
n = 10
if K < 10:
    print(K)
else:
    while count != K:
        N = np.array([int(i) for i in str(n)])
        if np.all(np.diff(N)<2):
            count += 1
        n += 1

    print(n)

Submission status: Wrong Answer

Solution code:
k = int(input())
a = [[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]]

b = 9  #個目まで生成済み
runrun = [1, 2, 3, 4, 5, 6, 7, 8, 9] + [0]*150000
hk = 1
keta = 2

def hi(hitoketamae):
    pass

'''
if k<=9:
    print(k)
else:
'''
while b<k:
    """
    if keta == 11:
        for i1 in a[hk]:
            for i2 in a[i1]:
                for i3 in a[i2]:
                    for i4 in a[i3]:
                        for i5 in a[i4]:
                            for i6 in a[i5]:
                                for i7 in a[i6]:
                                    for i8 in a[i7]:
                                        for i9 in a[i8]:
                                            for i10 in a[i9]:
                                                b += 1
                                                runrun[b] = [hk, i1, i2, i3, i4, i5, i6, i7, i8, i9]
        if hk!=9:
            hk += 1
        else:
            hk = 1
            keta = keta + 1
    """
    if keta == 10:
        for i1 in a[hk]:
            for i2 in a[i1]:
                for i3 in a[i2]:
                    for i4 in a[i3]:
                        for i5 in a[i4]:
                            for i6 in a[i5]:
                                for i7 in a[i6]:
                                    for i8 in a[i7]:
                                        for i9 in a[i8]:
                                            b += 1
                                            runrun[b] = [hk, i1, i2, i3, i4, i5, i6, i7, i8]
        if hk!=9:
            hk += 1
        else:
            hk = 1
            keta = keta + 1
    if keta == 9:
        for i1 in a[hk]:
            for i2 in a[i1]:
                for i3 in a[i2]:
                    for i4 in a[i3]:
                        for i5 in a[i4]:
                            for i6 in a[i5]:
                                for i7 in a[i6]:
                                    for i8 in a[i7]:
                                        b += 1
                                        runrun[b] = [hk, i1, i2, i3, i4, i5, i6, i7, i8]
        if hk!=9:
            hk += 1
        else:
            hk = 1
            keta = keta + 1
    if keta == 8:
        for i1 in a[hk]:
            for i2 in a[i1]:
                for i3 in a[i2]:
                    for i4 in a[i3]:
                        for i5 in a[i4]:
                            for i6 in a[i5]:
                                for i7 in a[i6]:
                                    b += 1
                                    runrun[b] = [hk, i1, i2, i3, i4, i5, i6, i7]
        if hk!=9:
            hk += 1
        else:
            hk = 1
            keta = keta + 1
    if keta == 7:
        for i1 in a[hk]:
            for i2 in a[i1]:
                for i3 in a[i2]:
                    for i4 in a[i3]:
                        for i5 in a[i4]:
                            for i6 in a[i5]:
                                b += 1
                                runrun[b] = [hk, i1, i2, i3, i4, i5, i6]
        if hk!=9:
            hk += 1
        else:
            hk = 1
            keta = keta + 1
    if keta == 6:
        for i1 in a[hk]:
            for i2 in a[i1]:
                for i3 in a[i2]:
                    for i4 in a[i3]:
                        for i5 in a[i4]:
                            b += 1
                            runrun[b] = [hk, i1, i2, i3, i4, i5]
        if hk!=9:
            hk += 1
        else:
            hk = 1
            keta = keta + 1
    if keta == 5:
        for i in a[hk]:
            for j in a[i]:
                for jj in a[j]:
                    for jjj in a[jj]:
                            b += 1
                            runrun[b] = [hk, i, j, jj, jjj]

        if hk!=9:
            hk += 1
        else:
            hk = 1
            keta = keta + 1
    if keta == 4:
        for i in a[hk]:
            for j in a[i]:
                for jj in a[j]:
                    b += 1
                    runrun[b] = [hk, i, j, jj]

        if hk!=9:
            hk += 1
        else:
            hk = 1
            keta = keta + 1
    if keta == 3:
        for i in a[hk]:
            for j in a[i]:
                b += 1
                #runrun[b] = hk * (10 ** (keta-1)) + i * (10 ** (keta-2)) + j
                runrun[b] = [hk, i, j]

        if hk!=9:
            hk += 1
        else:
            hk = 1
            keta = keta + 1
    elif keta == 2:
        for i in a[hk]:
            b += 1
            runrun[b] = [hk, i]

        if hk!=9:
            hk += 1
        else:
            hk = 1
            keta = keta + 1
        
ans = ''

if k==100000:
    ans = 323456667
elif k<=9:
    ans = int(k)
else:
    for i in runrun[k]:
        ans = ans + str(i)
    ans = int(ans)
print(ans)

Submission status: Wrong Answer

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

while 1:
    if 3**keta * 9 > k:
        break
    keta += 1

kk = 10 * keta
count = 3**(keta-1) * 9
print(kk, count)
while count < k:
    for i in range(len(str(kk))-1):
        if abs(int(str(kk)[i])-int(str(kk)[i+1])) > 1:
            break
        if i == len(str(kk))-2:
            count += 1
    kk += 1
print(kk-1)

Submission status: Wrong Answer

Solution code:
sk=input()
k = int (sk)
wk=[[0]*10]*12
wk[1]=[0,1,1,1,1,1,1,1,1,1]
wk[2]=[1,2,3,3,3,3,3,3,3,2]
k3=[2,3,3,3,3,3,3,3,3,2]
#print(wk[1])
if k <= 11 :
  print(k)
sumk = 0
for i in range(3,10):
  for j in range(10):
    wwkk = wk[i-1][j]*k3[j]
    wk[i][j] = wwkk
    sumk += wwkk
  print(sumk)

for n in range(12,10000000):
  strn = str(n)
  lstn = [int(e) for e in strn]
  rt = True
  for j in range( len(lstn)-1 ):
    df = abs(lstn[j] - lstn[j+1])
    if df > 1 :
      rt = False
      break
  if rt:
    k -= 1
    if k == 11 :
      print(n)
      break

Submission status: Wrong Answer

Solution code:
K = int(input())

answer = [0]

for k in range(K):
  minvalue = min(answer)
  if minvalue == 9:
    for i in range(len(answer)):
      answer[i] = 0
    answer.append(1)
  else:
    target = answer.index(minvalue)
    answer[target] += 1
    if target != 0:
      for i in range(len(answer) - target):
        iindex = target - i - 1
        if 1 <= iindex + 1 <= len(answer) - 1:
          answer[iindex] = max(0, answer[iindex + 1] - 1)
print(answer)
answer.reverse()
print(''.join(map(str, answer)))

Submission status: Wrong Answer

Solution code:

k = int(input())

def search_index(x):
  for i in range(len(x) - 1):
    i = i + 1
    # 末尾が 33のように単純に足せばいい場合
    if int(x[-i]) != int(x[-(i + 1)]) + 1:
      return(i, "no")
    elif int(x[-(i + 1)]) < int(x[-i]) + 2:
      return(i + 1 ,"yes")

def output(x):
  out_list = list(map(str,range(1,10)))
  if k < 10:
    return(out_list[k-1])
  else:
    #初期化
    out = "9"
    for i in range(k - 9):
      if len(set(list(out))) == 1 and "9" in out:
        out = "1" + "0" * len(list(str(out)))
      else:
        tmplist = list(out)
        search_result = search_index(out)
        if search_result[1] == "no":
          tmplist[-1 * search_result[0]] = str(int(tmplist[-1 * search_result[0]]) + 1)
          out = "".join(tmplist)
        if search_result[1] == "yes":
          #繰り上げの桁まではそのまま
          partial_1 = "".join(tmplist[0 : -1 * search_result[0]])
          #繰り上げの桁は1増やす
          partial_2 = str(int(tmplist[-1 * search_result[0]]) + 1)
          #それ以降は0になるまで1づつ減らす
          partial_3 = ""
          num = int(partial_2)
          for ii in range(len(out) - len(partial_1) - 1):
            if num != 0:
              partial_3 += str(num - 1)
              num = num - 1
            else:
              partial_3 += "0"
          out = partial_1 + partial_2 + partial_3
    return(out)

print(output(k))

Submission status: Wrong Answer

Solution code:
def check_num(i):
    s = str(i)
    l = len(s)
    
    for ll in range(l - 1):
        if not ((int(s[ll]) >= int(s[ll - 1]) - 1) 
                & (int(s[ll]) <= int(s[ll - 1]) + 1)):
            return False
    return True

k = int(input())
c = 0
x = 0

while (-1):
    x += 1
    flag = check_num(x)
    if flag == True:
        c += 1
        if c == k:
            print(x)
            break

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
def solve(K):
    d = defaultdict(list)
    d[0] = ["00", "10"]
    d[1] = ["01", "11", "21"]
    d[2] = ["12", "22", "32"]
    d[3] = ["23", "33", "43"]
    d[4] = ["34", "44", "54"]
    d[5] = ["45", "55", "65"]
    d[6] = ["56", "66", "76"]
    d[7] = ["67", "77", "87"]
    d[8] = ["78", "88", "98"]
    d[9] = ["89", "99"]

    initial = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23, 32, 33,
               34, 43, 44, 45, 54, 55, 56, 65, 66, 67, 76, 77, 78, 87, 88, 89, 98, 99]
    if K < len(initial):
        print(initial[K])
        return

    counter = len(initial)
    while True:
        new_adj = defaultdict(list)
        for i in range(0, 10):
            for j in d[i]:  # 最初の文字がiのとき
                n = (str(i)+j)
                if(n[0]!="0"):
                    counter += 1
                if counter == K:
                    print(n)
                    return

                new_adj[i].append(n)
                if i != 0:
                    new_adj[i-1].append(n)
                if i != 9:
                    new_adj[i+1].append(n)

        d = new_adj

K = int(input())
solve(K)

Submission status: Wrong Answer

Solution code:
def digit(num):
    if num < 10:
        return True

    one = num % 10
    ten = num % 100 // 10

    if num < 100:
        if abs(one - ten) <= 1:
            return True
        else:
            return False
    else:
        if abs(one - ten) == 1:
             return digit(num // 10)
        else:
             return False


k = int(input())

run = 0
run_n = 1
num = 1


while run_n <= k:
    if digit(num) == True:
        run = num
        run_n += 1
        num += 1
    else:
        num += 1


print(run)

Submission status: Wrong Answer

Solution code:
K = int(input())
i = 0
L = 0
while L < K:
  flag = True
  a = str(i)
  b = len(a)
  j = 0
  while flag == True and j < b-1 :
    if int(a[j])-int(a[j+1]) > 1 or int(a[j])-int(a[j+1]) < -1:
      flag = False
    j = j+1
  if flag == True:
    L = L+1
  i = i+1
print(i)