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())

dp = [[0]*10 for _ in range(17)]
for i in range(10):
    dp[0][i] = 1

for keta in range(1, 17):
    for i in range(10):
        if 1 <= i and i <= 8:
            dp[keta][i] += dp[keta-1][i-1]+dp[keta-1][i]+dp[keta-1][i+1]
        if i == 0:
            dp[keta][i] += dp[keta-1][0]+dp[keta-1][1]
        if i == 9:
            dp[keta][i] += dp[keta-1][9]+dp[keta-1][8]
SUM = 0
for keta in range(17):
    SUM += sum(dp[keta][1:])
    if SUM >= K:
        break
SUM = 0
for i in range(keta):
    SUM += sum(dp[i][1:])

r = K-SUM
tmp_r = 0
for i in range(1, 10):
    tmp_r += dp[keta][i]
    if tmp_r >= r:
        r = tmp_r - dp[keta][i]
        break
keta += 1
if keta == 1:
    print(i)
else:
    l=[i]
    rr = 0
    for k in range(keta-1, 0, -1):
        q = deque()
        if i == 0:
            q.append(0)
            q.append(1)
        elif i == 9:
            q.append(8)
            q.append(9)
        else:
            q.append(i-1)
            q.append(i)
            q.append(i+1)
        while q:
            num = q.popleft()
            rr += dp[k-1][num]
            if rr >= r:
                rr -= dp[k-1][num]
                l.append(num)
                i = num
                break
    print(l)

Submission status: Wrong Answer

Solution code:

# -*- coding: utf-8 -*-


K=int(input())

lis=[]
curmin=0
if K<10:
    print(K)

else:
    count=9
    alis=[]
    lis.append(1)
    for i in range(1,10):
        lis.append(1)
    alis.append(lis)
    keta=1
    while True:
        i=0
        lis=[]
        l0=alis[keta-1][0]+alis[keta-1][1]

        lis.append(l0)


        for i in range(1,9):
            l0=alis[keta-1][i-1]+alis[keta-1][i]+alis[keta-1][i+1]
            count+=l0
            #print(count)
            if count>=K:
                break
            lis.append(l0)
        if count>=K:
            break

        i=9
        l0=alis[keta-1][8]+alis[keta-1][9]
        count+=l0
        if count>=K:
            break
        lis.append(l0)

        keta+=1
        alis.append(lis)


    num=10**keta*i
    cur=K-(count-l0)
    for ki in reversed(range(0,keta)):
        count=0
        if i==0:
            for j in [0,1]:
                count+=alis[ki][i]
                if cur<=count:
                    cur-=count-alis[ki][i]
                    break
        if i==9:
            for j in [8,9]:
                count+=alis[ki][i]
                if cur<=count:
                    cur-=count-alis[ki][i]
                    break
        else:
            for j in [i-1,i,i+1]:
                count+=alis[ki][i]
                if cur<=count:
                    cur-=count-alis[ki][i]
                    break
        
        i=j
        num+=10**ki*i
    print(str(num))

Submission status: Wrong Answer

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

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

    if K <= 10:
        print(K)
        sys.exit()

    count = 9

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

    for disit in range(2,11):
        dp[disit][0] = pre
        pre = []
        for top in range(1,10):
            if top == 9:
                test = [top-1,top]
            else:
                test = [top-1,top,top+1]
            for k in test:
                temp = dp[disit-1][k]
                for l in temp:
                    res = l + top * 10 ** (disit - 1)
                    if res not in pre:
                        count += 1
                        pre.append(res)
                        dp[disit][top].append(res)
                    # print(count,temp)
                    if count == K:
                        print(res)
                        sys.exit()



main()

Submission status: Wrong Answer

Solution code:
k=int(input())

def judge(s):
    flag = 1
    s=list(set(s))
    if len(s)<=1: return 1
    for i in range(len(s)-1):
        s1, s2 = int(s[i]),int(s[i+1])
        if abs(abs(s1)-abs(s2)) <= 1: continue
        else:
            flag = 0 
            break
    return flag


def bfs1(k, cnt=1, now=1):
    while True:
        s=str(now)
        if judge(s) and k==cnt: return now
        elif judge(s):
            cnt+=1
            now+=1
        else: now+=1

def bfs2(k, cnt=100000, now=3234566667):
    while True:
        s=str(now)
        if judge(s) and k==cnt: return now
        elif judge(s):
            cnt-=1
            now-=1
        else: now-=1    

# print(bfs1(k,1,1))
if k<1000: print(bfs1(k,1,1))
else: print(bfs2(k))

Submission status: Wrong Answer

Solution code:
N = int(input())

def is_lunlun(x):
    if x < 10:
        return True
    elif abs(int(str(x)[0])- int(str(x)[1])) > 1:
        return False
    else:
        return is_lunlun(int(str(x)[1:]))


K = 1
num = 1
while True:
    if is_lunlun(num + 1):
        K += 1
        num = num + 1
    else:
        K += 1
        num = num + 9
    if K >= N:
        break
print(num)

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
answer=0
for t in range(0,10):
  answer=answer+A[9-t]*10^(9-t)
print(answer)

Submission status: Wrong Answer

Solution code:
# 2020/04/04
# AtCoder Beginner Contest 161 - D

runsu = list()

def makerunrun(s):

    if int(s) > 3234566667:
        return 0

    runsu.append(int(s))
    lketa = int(s[len(s)-1])
    if lketa > 0:
        wks = s + str(lketa - 1)
        makerunrun(wks)
    
    wks = s + str(lketa)
    makerunrun(wks)
    
    if lketa < 10:
        wks = s + str(lketa + 1)
        makerunrun(wks)
    
# Input
k = int(input())

# Make Runrun List
for i in range(1, 10):
    makerunrun(str(i))

runsu.sort()

# Output
print(runsu[k-1])

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")
    # 末尾が 34のように繰り上げなきゃいけない場合
    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)
        elif 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 c(N):
    i = 2
    while i ** 2 <= N:
        if N % i == 0:
            return False
        i += 1
    return True

def main():
    K = int(input())
    ans = 0
    count = 0

    while ans < K:

        count += 1
        if count < 10:
            ans += 1
        else:
            tmp_c = count // 10
            if (count - tmp_c) < 10:
                ans += 1
            elif (count - tmp_c) % 11 == 0:
                ans += 1
            elif str(count - tmp_c)[-1] == "9":
                ans += 1
            elif str(count - tmp_c)[-1] == "0":
                ans += 1
            elif str(count - tmp_c)[-1] == "1":
                ans += 1

    print(count)

    return 0


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

k = input()
k = int(k)

runrun_count = 0
i = 0
ok = True

while runrun_count < k :

    i = str(i)

    # 場合分け
    if int(i) < 10 :
        runrun_count = runrun_count + 1

    if 10 <= int(i) < 100 : 
        if abs(int(i[1]) - int(i[0])) <= 1 :
            # print('カウント!')
            runrun_count = runrun_count + 1

    if 100 < int(i) :

        for j in range(1, len(i) - 1):
            if abs(int(i[j]) - int(i[j - 1])) > 1 :
                ok = False

        if ok == True : 
            runrun_count = runrun_count + 1

        ok = True    

    i = int(i) + 1



print(i)

Submission status: Wrong Answer

Solution code:

k=int(input())

res=0 
count=10
n=0
new_l=[1,2,3,4,5,6,7,8,9,10]
'''
num_list=list(range(11,10**6))
for n in num_list:
    n = list(map(int, str(n)))
    if max(n)-min(n)>= len(n):
        n=int("".join(map(str, n)))
        num_list.remove(n)
        '''

for i in range(11,10**6):
    i = list(map(int, str(i)))
    for n in range(len(i)-1):
        num=0
        if abs(i[n]-i[n+1])<=1:
            num+=1    
        else:
            break


        if num==len(i)-1:  
            i=int("".join(map(str, i)))
            new_l.append(i)
    
            if len(new_l)==k:
                print(new_l[-1])
            exit()

Submission status: Wrong Answer

Solution code:
K = int(input())  #数字

if K <= 12:
    print(K)
    exit()

num = 13
cou = 12
cal = 1
while cou < K:
    L = list(map(int, str(num)))  #iの各行を数字としてリストに格納し合計
    print("num", num)
    #print(cal)
    for i in range(len(L) - 1):
        if abs(L[i] - L[i + 1]) > 1:
            num += 1
            break
        else:
            if cal == len(L) - 1:
                cou += 1
                num += 1
                cal = 1              
            else:
                cal += 1
    #print(cou)
print(num-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
Q=[1,2,3,4,5,6,7,8,9]
while(Q!=[] and n>1):
  a=Q.pop(0)
  n-=1;
  if(n>1):
    t=a%10
    Q.append(a*10+(t-1));
    Q.append(a*10+t);
    Q.append(a*10+(t+1));
a=Q.pop(0)
if(a<3234566667):
  print(a)
else:
  print(3234566667)

Submission status: Wrong Answer

Solution code:
def main():
    k=int(input())
    ans=[0]*100000
    #max:3234566667≒10^9
    for i in range(100000):
        tmp=0
        tmp2=0
        tmp3=0
        tmp4=0
        if i>11:
            tmp=ans[i-1]+1
            #if int(str(tmp)[-1])==9 :
            #    tmp+=int(str(tmp)[-2])+1
            tmp2=tmp
            for j in range(1,len(str(tmp))):
                if abs(int(str(tmp)[-j])-int(str(tmp)[-(j+1)]))>1:
                    tmp4=10**(j-1)*(int(str(tmp)[-j])-2)
                    tmp3=10**(j-1)*int(str(tmp)[-j])
                    tmp=tmp-10**(j-1)*int(str(tmp)[-j])
                    tmp+=tmp4
                    tmp+=10**j
                    
        else:
            tmp=i+1
        #if i>34:
        #    print(ans[i-1]+1,tmp,tmp2,tmp3,tmp4)
        ans[i]=tmp
    
    print(ans[k-1])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
k=int(input())

def judge(s):
    flag = 1
    s=list(set(s))
    if len(s)<=1: return 1
    for i in range(len(s)-1):
        s1, s2 = int(s[i]),int(s[i+1])
        if abs(abs(s1)-abs(s2)) <= 1: continue
        else:
            flag = 0 
            break
    return flag


def bfs1(k, cnt=1, now=1):
    while True:
        s=str(now)
        if judge(s) and k==cnt: return now
        elif judge(s):
            cnt+=1
            now+=1
        else: now+=1

def bfs2(k, cnt=100000, now=3234566667):
    while True:
        s=str(now)
        if judge(s) and k==cnt: return now
        elif judge(s):
            cnt-=1
            now-=1
        else: now-=1    

print(bfs1(k,1,1))
# if k<1000: print(bfs1(k,1,1))
# else: print(bfs2(k))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from copy import deepcopy
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

K = read_int()[0]

prev = [1 for _ in range(10)]
next = [0 for _ in range(10)]
log = []
def solve():
    all = 9
    prevall = 0
    while all < K:
        for i in range(10):
            if i == 0:
                next[i] = prev[i] + prev[i + 1]
            elif i == 9:
                next[i] = prev[i - 1] + prev[i]
            else:
                next[i] = prev[i - 1] + prev[i] + prev[i + 1]
        # all += sum(next)
        # print(all)
        log.append(deepcopy(prev))
        # print(next)
        for i in range(10):
            prev[i] = next[i]
        prevall = all
        all += sum(prev) - prev[0]
    # print(all, prevall)
    log.append(deepcopy(prev))

    d = []
    # while True:
    log.reverse()
    nd = 1
    for l in log:
        for i in range(nd, 10):
            if prevall + l[i] >= K:
                d.append(str(i))
                nd = max(1, i - 1)
                # print(nd)
                break
            prevall += l[i]
            # print(i, prevall)
        # print(prevall)
    # print(d)
    return d

if __name__ == "__main__":
    res = solve()
    ans = ''.join(res)
    print(ans)

Submission status: Wrong Answer

Solution code:
# 2020/04/04
# AtCoder Beginner Contest 161 - D

runsu = list()

def makerunrun(s):

    if int(s) > 3234566667:
        return 0

    runsu.append(int(s))
    lketa = int(s[len(s)-1])
    if lketa > 0:
        wks = s + str(lketa - 1)
        makerunrun(wks)
    
    wks = s + str(lketa)
    makerunrun(wks)
    
    if lketa < 10:
        wks = s + str(lketa + 1)
        makerunrun(wks)
    
# Input
k = int(input())

# Make Runrun List
for i in range(1, 10):
    makerunrun(str(i))

runsu.sort()

for i in range(500):
    print(runsu[i])

# Output
print(runsu[k-1])

Submission status: Wrong Answer

Solution code:
K = int(input())
dig = len(str(K))
count = 0
finish = False
broke = False
for i in range(1,10):
    count += 1
    if count == K:
        finish = True
        ans = i
        break
for i in range(1,30):
    if finish == True:
        break
    ran = 3 * (10 ** (i-1))
    for j in range(1,10):
        temp =(j * (10 ** i) + ((j-1)) * (10 ** (i-1)))
        for k in range(temp, temp+ran):
            tempdig = len(str(temp))-1
            for l in range(1, tempdig):
                if abs(int(str(temp)[l])-int(str(temp)[l-1])) > 1 or abs(int(str(temp)[l])-int(str(temp)[l+1])) > 1:
                    broke = True
                    break
            if broke == False:
                count += 1
                if count == K:
                    finish = True
                    ans = k
                    break
        if finish == True:
            break
    if finish == True:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
K = int(input())

dp = [[0 for i in range(10)] for j in range(100)]

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

p = 1
c = 0
a = 0

while c == 0:
  for n in range(10):
    if n != 0 and n != 9:
      dp[p+1][n] = dp[p][n]+dp[p][n-1]+dp[p][n+1]+dp[p][9]
    if n == 9:
      dp[p+1][n] = dp[p][n]+dp[p][n-1]+dp[p][9]
    if dp[p+1][n] >= K:
      c = dp[p+1][n]
      a = n
      break
    #0の追加は最後
    if n == 0:
      dp[p+1][n] = dp[p][1] + dp[p][0]

s = str(a)
for k in range(p,0,-1):

  if a != 0 and a != 9:
    for j in [1,0,-1]:
      c = c - dp[k][a+j]
      if c < K:
        s = s + str(a+j)
        break
  
  if a == 0:
    for j in [1,0]:
      c = c - dp[k][a+j]
      if c < K:
        s = s + str(a+j)
        break

  if a == 9:
    for j in [0,-1]:
      c = c - dp[k][a+j]
      if c < K:
        s = s + str(a+j)
        break       
print(int(s))

Submission status: Wrong Answer

Solution code:
def genar(ar,ma):
    ma = ma
    for i in range(ma):
        ar.append([0,0,0,0,0,0,0,0,0,0])
        ar[-1][0] = ar[-2][0] + ar[-2][1]
        for i in range(8):
            ar[-1][i+1] = ar[-2][i] + ar[-2][i+1] + ar[-2][i+2]
        ar[-1][-1] = ar[-2][-1] + ar[-2][-2]
    return ar

def main(k):
    ari = [[0,1,1,1,1,1,1,1,1,1]]
    ar = genar(ari,15)
    ans = []
    ketasuu = 1
    while k > sum(ar[ketasuu-1]):
        k = k-sum(ar[ketasuu-1])
        ketasuu = ketasuu + 1
    ans = []
    for i in range(ketasuu):
        for j in range(10):
            f = [0,0,0,0,0,0,0,0,0,0]
            f[j] = 1
            if i != 0 and j != 0:
                newaa = genar([f],ketasuu-i)[-1]
                if sum(newaa) >= k:
                    ans.append(j)
                    j = 10
                    break
                else:
                    k = k - sum(newaa)
    ans.append(k)
        
    ret = 0
    for i in range(len(ans)):
        ret = ret*10+ans[i]
    return ret
        
    
k = int(input())

lunlun = main(k)
print(lunlun)

Submission status: Wrong Answer

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


k = int(input())
number = 9

ans = 0
for i in range(10,10**7):
    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
            break
    break
if k <= 9:
    print(k)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
K=int(input())
i=0
current_num=0
while (i<K) :
  current_string=str(current_num)
  flag=True
  for k in range(len(current_string)-1) :
    if abs(int(current_string[k])-int(current_string[k+1]))>1 :
      flag=False
      break
  if flag==True :
    i+=1
  current_num+=1
  
print(current_num)

Submission status: Wrong Answer

Solution code:
import itertools

def add_num(A):
    B=[[],[],[],[],[],[],[],[],[]]
    for i in A:
        for j in i:
            if j[0]=='1':
                B[0].append('1'+j)
                B[1].append('2'+j)
            if j[0]=='2' or j[0]=='3' or j[0]=='4' or j[0]=='5' or j[0]=='6' or j[0]=='7' or j[0]=='8':
                B[int(j[0])-2].append(str(int(j[0])-1)+j)
                B[int(j[0])-1].append(j[0]+j)
                B[int(j[0])].append(str(int(j[0])+1)+j)
            if j[0]=='9':
                B[7].append('8'+j)
                B[8].append('9'+j)
    return B


K=int(input())

A=[[str(i)] for i in range(1,10)]
while sum([len(item) for item in A]) <=K:
    A=add_num(A)
    
ans=list(itertools.chain.from_iterable(A))
print(ans[K-1])

Submission status: Wrong Answer

Solution code:
def Lunlun(n):
  ans = True
  str_n = str(n)
  for i in len(str_n)-1:
    if abs(int(str_n[i])-int(str_n(i+1))) != 1:
      ans = False
      break
  return ans
    

K = int(input())
i = 0
cnt = 0
while cnt==K:
  i = i+1
  if Lunlun(i)==True:
    cnt = cnt+1

print(i)

Submission status: Wrong Answer

Solution code:
k = int(input())
 
if 10 > k:
  print(k)
else:
  b = 10
  ans = 9
  st = ''
  while True:
    old = st
    st=str(b)
    for i in range(len(st)-1):
      if abs(int(st[i])-int(st[i+1])) > 1:
        #b = b + 9**(len(st)-i)
        if old != st:
          b = b + 1
        else:
          b = b + 9 * (10**(len(st)-1-i))
        break
    else:
      ans +=1
      b +=1
      #print('ans',ans,b)
    if ans == k:
      break
  print(b)

Submission status: Wrong Answer

Solution code:
k = int(input())
listA = [1,2,3,4,5,6,7,8,9,10,11,12]
# k = int("15")
n = 1
z = 12

q = k // z
mod = k % z
print(str(q + 1)+ str(listA[mod - 1]))

# for i in range(k):

# print([1,2,3,4,5,6,7,8,9,10,11,12,21,22,23,24,25,26,27,28,29,210,211,212][int(input()) - 1])

Submission status: Wrong Answer

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

'''
100000
99990
90000
'''

K = int(input())
K = 100000 - K
c = list(str(3234566667))
c = [int(i) for i in c][::-1]

for i in range(K):
    keta = len(c)
    # print(c)

    for ket in range(keta):
        if ket == keta - 1:
            if c[ket] > 1:
                c[ket] = c[ket] - 1
                for j2 in range(ket - 1):
                    c[ket - j2 - 1] = c[ket - j2 - 1] + 1
                break
            else:
                for j2 in range(ket - 1):
                    c[ket - j2 - 1] = 9
                c = c[:-1]
                break

        if c[ket] == 0:
            continue

        if c[ket] >= c[ket + 1]:
            c[ket] = c[ket] - 1

            for j in range(ket):
                if c[ket] == 9:
                    c[ket - j - 1] = 9
                elif c[ket] == 0 and c[ket + 1] == 0:
                    c[ket - j - 1] = 0
                else:
                    if c[ket - j] == 9:
                        c[ket - j - 1] = 9
                    else:
                        c[ket - j - 1] = c[ket - j] + 1
            break


[print(int(i), end='') for i in c[::-1]]
print('')

Submission status: Wrong Answer

Solution code:
K=int(input())
n=1
c=0
while 1:
  j=True
  n_str=str(n)
  for i in range(len(n_str)-1):
    if abs(int(n_str[i]) - int(n_str[i+1])) > 1:
      j=False
  if j:
    c+=1
  if c==K:
    print(n)
    break
  if len(n_str) > 1 and abs(int(n_str[0]) - int(n_str[1])) > 1:
    n = (int(str(int(n_str[0])+1)+str(int(n_str[0]))))*(10**(len(n_str)-2))
  else:
    n+=1

Submission status: Wrong Answer

Solution code:
k = int(input())
table = [0] * (k+1)
for i in range(1,k+1):
    bad = True
    table[i] = table[i-1] + 1
    for j in range(len(str(table[i]))-1):
        if abs(int(str(table[i])[j]) - int(str(table[i])[j+1])) > 1:
            m = len(str(table[i]))
            for l in range(m-j):
                if l == 0:
                    table[i] += 10**(m-j-1)
                else:
                    table[i] -= (2 * (10 ** (m-j-1-l)))
print(table[k])

Submission status: Wrong Answer

Solution code:
k = int(input())
cnt = 0
for i in range(1,10**5+1):
    #print(str(i))
    l = len(str(i))
    if l == 1:
        cnt+=1
        #print(i,cnt)
    flag = False
    #print(str(i)[0])
    for j in range(l-1):
        if int(str(i)[j+1])-int(str(i)[j]) <= 1:
           flag = True
        else:
           break
    if flag:
        cnt +=1
        #print(i,cnt)
    if cnt == k:
        if k <=12:
            print(i)
        else:
            print(i+1)

Submission status: Wrong Answer

Solution code:
k = int(input())

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

Submission status: Wrong Answer

Solution code:
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  k= int(readline())
  if k<10:
    print(k)
    sys.exit()
  dp = np.ones((10,10), dtype='int64')
  #dp[i-1][j]は、i桁のときの末尾がjの数
  dp[0, 0] = 0
  for i in range(9):
    for j in range(10):
      if j == 0:
        dp[i+1,0] = dp[i,0] + dp[i,1]
      elif j == 9:
        dp[i+1,j] = dp[i,8] + dp[i,9]
      else:
        dp[i+1,j] = dp[i,j-1] + dp[i,j] + dp[i,j+1]
  total = [0]
  #i桁のときの数の累積和
  for i in range(10):
    tmp = total[-1] + dp[i,:].sum()
    total.append(tmp)
  keta = 0
  for i in range(11):
    if total[i]<=k:
      keta = i+1
  #kはketa桁である
  c = 10**(keta-1)
  count = total[keta-1]
  for i in range(c,c*10):
    s = str(i)
    bl = True
    for j in range(keta-1):
      if abs(int(s[j])-int(s[j+1]))>1:
        bl=False
    if bl:
      count +=1
    if count == k:
      sys.exit()
  
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
# k = int(input())
listA = [1,2,3,4,5,6,7,8,9,10,11,12]
k = int("15")
n = 1
z = 12

q = k // z
mod = k % z
print(str(q + 1)+ str(listA[mod - 1]))

# for i in range(k):

# print([1,2,3,4,5,6,7,8,9,10,11,12,21,22,23,24,25,26,27,28,29,210,211,212][int(input()) - 1])

Submission status: Wrong Answer

Solution code:
n = int(input())
m = n
order = 0
while m > 3:
    m = m / 3
    order += 1
rem = n - 3**order
msb = rem // 3
lsb = rem % 3
if lsb == 0:
    lsb = msb + 1
elif lsb == 2:
    lsb = msb
elif lsb == 1:
    lsb =  msb - 1
print(msb*10+lsb)

Submission status: Wrong Answer

Solution code:
K = int(input())
N = 10
count = [9]
i = 1
buf = 0

if K <= 9 : # 例外
    print(K)

else :
    FLAG = True
    while FLAG :
        buf = 3 * (count[i-1] - i) + 2 * i
        count.append(buf) # i桁目に含まれる総数
        if count[i-1] <= K <= count[i] :
            FLAG = False
        else :
            i += 1

    #print(count)
    #print(i+1) # lunlun はlen(list(str(count[i-1])))桁の整数
    #print(K-count[i-1])
    # lunlunは， i桁で，K-count[i-1]個目のlunlun
    #print("--")
    cnt = 0
    for j in range(10**(i),10**(i+1)) :
        for k in range(i) :
            if abs(int((list(str(j))[k])) - int((list(str(j))[k+1]))) > 1 :
                #print("c")
                break
            cnt += 1
        if cnt + count[i-1] == K :
            print(j)
            break

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 + 300:
        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:
k = int(input())

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

Submission status: Wrong Answer

Solution code:
K=int(input())
count=0

for i in range(1,3234566667):
    flg=True
    s=str(i)
    v=list(map(int,s))
    for j in range(len(v)-1):
        if abs(v[j]-v[j-1])>=2:
            flg=False
            break
    if flg:
        count+=1
    if count==K:
        print(i)
        exit(0)

Submission status: Wrong Answer

Solution code:
import numpy as np
K=int(input())

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,:])+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]
isrunrun = True

for i in range(1,100000):

    run = str(i)
    for j in range(len(run)-1):
        if(abs(int(run[j])-int(run[j+1])) > 1):
            isrunrun = False
        else:
            runrun.append(i)
  
print(runrun[k-1])

Submission status: Wrong Answer

Solution code:
K = int(input())
# ルンルン数を前計算したい。
M = [i for i in range(1,11)]
cnt = 0
U = list(M)
while(True):
    nex = set()
    tmp = set(M)
    for m in U:
        if str(m)[0] == "1":
            a = int("10"+str(m))
            b = int("1"+str(m))
            c = int("2"+str(m))
            if a not in tmp:nex.add(a)
            if b not in tmp:nex.add(b)
            if c not in tmp:nex.add(c)
        elif str(m)[0] == "0":
            a = "1"+str(m)
            if a not in tmp:nex.add(a)
        else:
            for i in range(int(str(m)[0])-1,int(str(m)[0])+2):
                a = int(str(i)+str(m))
                if a not in tmp:nex.add(a)
    M = list(tmp|nex)
    U = list(nex)
    if len(M) >= 10**5+1:
       break
M = set(M)
M = list(sorted(list(M)))
print(M[K-1])