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

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(cur):
            # start: fixed
            ss = str(cur)
            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(int(ss[1:]))
            elif int(ss[0]) == int(ss[1]):
                ret = nums[len(ss) - 1][int(ss[1]) - 1]
                return ret + dfs(int(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(int(ss[1:]))
            else:
                return nums[len(ss)][int(ss[0])]

        return ret + dfs(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())
ans = []
i = 1

while len(ans) < K :
  l = len(str(i)) - 1
  que = 'yes'
  for k in range(l):
    a = str(i)
    if abs( int(a[k])- int(a[k+1]) ) >= 2:
      que = 'no'
      break

  if que == 'yes':
    ans = ans + [i]
    print(i)

  i +=1

print(i)

Submission status: Wrong Answer

Solution code:
N = int(input())


def check(a):
    s = str(a)
    if len(s) == 1:
        return True
    
    for i in range(1, len(s)):
        if abs(int(s[i-1]) - int(s[i])) > 1:
            return False
    return True
    
def solve(N):
    m = 10**5
    ct = 0
    for i in range(1, m+1):
        if check(i):
            ct += 1
            if ct == N:
                return i

print(solve(N))

Submission status: Wrong Answer

Solution code:
K = int(input())

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

memo = [[1]*10] + [[1]*10 for _ in range(9)]

n = 9
digit = 1
i = -1
ans = []
while True:
    i += 1
    if i == 10:
        i = 0
        digit += 1
    tmp = memo[digit-1][i]
    if i >= 1:
        tmp += memo[digit-1][i-1]
    if i <= 8:
        tmp += memo[digit-1][i+1]
    memo[digit][i] = tmp
    if i != 0:
        if n + tmp >= K:
            while digit >= 0:
                t = memo[digit][i]
                #if n + t == K:
                #    ans.append(i)
                #    for d in range(digit):
                #        ans.append(min(9, i+d))
                #    break
                if n + t >=  K:
                    ans.append(i)
                    digit -= 1
                    i = i-1
                else:
                    n += t
                    i += 1
            break
        else:
            n += tmp

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import sys

sys.setrecursionlimit(10**9)

def check(n):
    r = 1
    b = None
    if n == 1:
        return 1
        
    while n > 0:
        num = r
        if num < 10:
            n -= 1
            r += 1
        else:
            is_comp=True
            ng_n = 0
            while num > 0:
                m = num % 10
                num = num // 10
                ng_n += 1
                if b and abs(m-b) > 1:
                    is_comp=False
                    break
                b = m
            if is_comp:
                n -= 1
                r += 1
            else:
                g = 10**ng_n
                r = r // g * g + g
            
    return r

K = int(input())

print(check(K))

Submission status: Wrong Answer

Solution code:
K = int(input())
l = [x for x in range(1,11)]
if K <= 10:
  print(K)
for i in range(1,K-9):
  num = 10+ 9 *((i) // 3) + i - (i//3)
  if l[i+9-1] % 10 == 0:
    l.append(l[i+9-1]+1)
  else:
    l.append(num)
    
print(l[K-1])

Submission status: Wrong Answer

Solution code:
def lunlun(x):
    c=0
    l=list(str(x))
    for i in range(len(l)):
        l[i]=int(l[i])
    l.sort()
    c=0
    for i in range(1,len(l)):
        if abs(l[i]-l[i-1])<=1:
            c=c+1
    if c==len(l)-1:
        return True
    else:
        return False
    
n=int(input())
c=0
i=1
while c!=n:
    if lunlun(i):
        c=c+1
    i=i+1
print(i-1)

Submission status: Wrong Answer

Solution code:
import numpy as np

k = int(input())


def get_top(rem):
    number = 0

    numbers = np.zeros((100,10), dtype=np.int64)
    numbers[0] += 1
    for i in range(100):
        for j in range(10):
            if j == 0:
                numbers[i+1][j] = numbers[i][j] + numbers[i][j+1]
            elif j == 9:
                numbers[i+1][j] = numbers[i][j-1] + numbers[i][j]
                number += numbers[i+1][j]
            else:
                numbers[i+1][j] = numbers[i][j-1] + numbers[i][j] + numbers[i][j+1]
                number += numbers[i+1][j]
            if number >= rem:
                break
        if number >= rem:
            break
    return i, j, k-(number - numbers[i+1][j]), numbers


def get_after_second(top, remains):
    pass

ans = ""

if k <= 9:
    print(k)
else:
    k -= 9
    dig, top, remain, nums = get_top(k)
    ans += str(top)
    for i in range(dig+1):
        digit = dig - i
        if not top == 0:
            second_top = top - 1
            for j in range(3):
                if remain - nums[digit][second_top + j] <= 0:
                    top = second_top + j
                    break
                else:
                    remain -= nums[digit][second_top + j]
        else:
            second_top = top
            for j in range(2):
                if remain - nums[digit][second_top + j] < 0:
                    top = second_top + j
                    break
                else:
                    remain -= nums[digit][second_top + j]
        ans += str(top)
    print(ans)

Submission status: Wrong Answer

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

if k+1 <= cnt:
    print(q[k-1])

while True:
    if cnt >= k:
        break
    num = q.pop(0)
    list_num = list(num)
    a = int(list_num[-1])
    for i in range(10):
        if abs(a-i) < 2:
            cnt += 1
            if i == 0:
                q.append(num+"0")
            elif i == 1:
                q.append(num +"1")
            elif i == 2:
                q.append(num +"2")
            elif i == 3:
                q.append(num+"3")
            elif i == 4:
                q.append(num+"4")
            elif i == 5:
                q.append(num+"5")
            elif i == 6:
                q.append(num+"6")
            elif i == 7:
                q.append(num+"7")
            elif i == 8:
                q.append(num+"8")
            elif i == 9:
                q.append(num+"9")


print(q[k-cnt-1])

Submission status: Wrong Answer

Solution code:
def dp():
    cnt = []
    for i in range(10):
        cnt.append([0] * 10)
    for i in range(10):
        cnt[0][i] = 1
    for i in range(1, 10):
        for j in range(10):
            cnt[i][j] = cnt[i-1][j]
            if j > 0:
                cnt[i][j] += cnt[i-1][j-1]
            if j < 9:
                cnt[i][j] += cnt[i-1][j+1]
    return cnt


def isLunlunNumber(n):
    d = n % 10
    while n > 0:
        if abs(d - (n % 10)) > 1:
            return False
        d = n % 10
        n //= 10
    return True


def main():
    k = int(input())
    cnt = dp()
    tot = [0] * 10
    for i in range(10):
        tot[i] = sum(cnt[i][1:])
    # print(*cnt, sep='\n')
    # print(tot)

    res = 0
    length = -1
    digit = -1
    for i in range(10):
        if tot[i] < k:
            k -= tot[i]
        else:
            length = i
            for j in range(1, 10):
                if k > cnt[i][j]:
                    k -= cnt[i][j]
                else:
                    digit = j
                    break
            break

    length -= 1
    res = digit
    while length >= 0:
        for i in range(-1, 2):
            if 0 <= digit + i and digit + i <= 9 and cnt[length][digit + i] >= k:
                digit = digit + i
                break
            else:
                k -= cnt[length][digit + i]
        length -= 1
        res = res * 10 + digit
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
k = int(input())
count = 1
i = 1
ans = 1
while count < k:
    flag = True
    s = str(i)
    for n in range(len(s) - 1):
        if i >= 10:
            if abs(int(s[n + 1]) - int(s[n])) > 1:
                flag = False
                n = len(str(i))
    if flag:
        count += 1
    i += 1
print(i)

Submission status: Wrong Answer

Solution code:
k=int(input())
count=0
def rec(l,keta,countive,s):
    global count
    global k
    #count
    if keta==1:
        if countive:
            count+=1
            if count==k:
                print(s.replace("0",""))
                return True #end flag
    #create next
    else:
        if l==0:
            if countive==False:#all l
                if rec(0,keta-1,False,s+str(0)):return True
                for i in range(1,10):
                    if rec(i,keta-1,True,s+str(i)):return True
            else:
                if rec(l,keta-1,True,s+str(l)):return True
                if rec(l+1,keta-1,True,s+str(l+1)):return True
        elif l==9:
            if rec(l-1,keta-1,True,s+str(l-1)):return True
            if rec(l,keta-1,True,s+str(l)):return True
        else:
            if rec(l-1,keta-1,True,s+str(l-1)):return True
            if rec(l,keta-1,True,s+str(l)):return True
            if rec(l+1,keta-1,True,s+str(l+1)):return True
rec(0,11,False,"0")

Submission status: Wrong Answer

Solution code:
K=int(input())
A=["1","2","3","4","5","6","7","8","9"]
B=[]
C=A[:]
count=9
if(K<10):
  print(K)
else:
  while(count<K):
    B=[]
    for i in range(len(C)):
      if(int(C[i][len(C[i])-1])==0):
        B.append(C[i]+str(0))
        B.append(C[i]+str(1))
        count+=2
      elif(int(C[i][len(C[i])-1])>0 and int(C[i][len(C[i])-1])<9):
        B.append(C[i]+str(int(C[i][len(C[i])-1])-1))
        B.append(C[i]+str(int(C[i][len(C[i])-1])))
        B.append(C[i]+str(int(C[i][len(C[i])-1])+1))
        count+=3
      else:
        B.append(C[i]+str(8))
        B.append(C[i]+str(9))
        count+=2
    C=B[:]
    A.extend(B)
print(A[K-1])

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 = [[0]]
R_list.append(R)
n = 9
d = 1
while n < X:
    list1 = R_list[-2] 
    list1 = list(map(lambda x: x + 10**d, list1) )
    list_ = [10 ** d]
    list_.extend(list1)
    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])

Submission status: Wrong Answer

Solution code:
K=int(input())

if(K>=13):
    print(((K-1)//3-3)*8+K)
else:
    print(K)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

def dil(i):
    if 1<=i<=8:
        return [i-1,i,i+1]
    if i==0:
        return [0,1]
    if i==9:
        return [8,9]

K = I()

#dp[i][j][k]:i桁，スタートj,ラストk
dp = [[[0]*10 for _ in range(10)] for _ in range(12)]
for i in range(1,10):
    dp[1][i][i] = 1

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

#dp2[i][j]: i桁，スタートjのルンルン数の総数
dp2 = [[0]*10 for _ in range(12)]
for i in range(12):
    for j in range(1,10):
        dp2[i][j] = sum(dp[i][j])

i = 1
aa = 0
while 1:
    if aa+sum(dp2[i]) >= K:
        L = i
        break
    aa += sum(dp2[i])
    i += 1

for i in range(L):
    K -= sum(dp2[i])

temp = 0
now = 0
ans = ''
dl = [i for i in range(10)]
for l in range(L):
    last_j = dl[0]
    for j in dl:
        if temp+now+dp2[L-l][j]>=K:
            break
        else:
            now += dp2[L-l][j]
            last_j = j+1
    ans += str(last_j)
    temp = temp+now
    now = 0
    dl = dil(last_j)

print(int(ans))

Submission status: Wrong Answer

Solution code:
k = int(input())
mark = 0
if(k<13):
  print(k)
else:
  cnt = 12
  for i in range(21, 100000000000):
    if(i>mark):
        flg = 0
        str_num = str(i)
        for j in range(0,len(str_num)-1):
          dif = abs(int(str_num[j]) - int(str_num[j+1]))
          if(dif>1):
            flg = 1
            mark = i+8
            break
        if(flg == 0):
          cnt += 1
        if(cnt == k):
          print(i)
          break

Submission status: Wrong Answer

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

k = int(input())
count = 0
for i in range(1, 10**5):
    s = str(i)
    if runrun(s):
        count += 1
    if count == k:
        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:
    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:
n = int(input())

count = 0
for k in range(2, n+1):
    b = n
    while b > 1:
        if b % k == 0:
            b = b//k
        else:
            b = b-k
    if b == 1:
        count += 1
print(count)

Submission status: Wrong Answer

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

while K != 0:
  
  if X <= 9:
    K -= 1
    X += 1
    continue
  
  for i in range(len(str(X))-1):
    if int(str(X)[i+1]) - 1 <= int(str(X)[i]) <= int(str(X)[i+1]) + 1:
      K -= 1
      X += 1
    else:
      X += 1

print(X)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

def dil(i):
    if 1<=i<=8:
        return [i-1,i,i+1]
    if i==0:
        return [0,1]
    if i==9:
        return [8,9]

K = I()

#dp[i][j][k]:i桁，スタートj,ラストk
dp = [[[0]*10 for _ in range(10)] for _ in range(12)]
for i in range(1,10):
    dp[1][i][i] = 1

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

#dp2[i][j]: i桁，スタートjのルンルン数の総数
dp2 = [[0]*10 for _ in range(12)]
for i in range(12):
    for j in range(1,10):
        dp2[i][j] = sum(dp[i][j])

i = 1
while 1:
    if sum(dp2[i]) >= K:
        L = i
        break
    i += 1

for i in range(L):
    K -= sum(dp2[i])

temp = 0
now = 0
ans = ''
dl = [i for i in range(10)]
for l in range(L):
    last_j = dl[0]
    for j in dl:
        if temp+now+dp2[L-l][j]>=K:
            break
        else:
            now += dp2[L-l][j]
            last_j = j+1
    ans += str(last_j)
    temp = temp+now
    now = 0
    dl = dil(last_j)

print(int(ans))

Submission status: Wrong Answer

Solution code:
k = int(input())
c = 0
x = 0
sx = 0
while c < k:
  sx = str(x)
  c+=1
  for i in range(len(sx)-1):
   if abs(int(sx[i]) - int(sx[i+1])) > 1:
     c-=1
     break
  x+=1
print(x)

Submission status: Wrong Answer

Solution code:
K = int(input())
X = 1

while K != 0:
  
  if X <= 9:
    K -= 1
    X += 1
    continue
  
  for i in range(len(str(X))-1):
    if int(str(X)[i+1]) - 1 <= int(str(X)[i]) <= int(str(X)[i+1]) + 1:
      K -= 1
      X += 1
    else:
      X += 1

print(X)

Submission status: Wrong Answer

Solution code:
import json
k = int(input())
# 1
# 2
# 3
# 10

# assume_valid
# list of num ??
def next_lunlun(k):
    k[0] += 1
    for i in range(len(k) - 1):
        if k[i] < 10:
            break
        k[i] -= 10
        k[i+1] += 1

    if k[-1] >= 10:
        k[-1] -= 10
        k.append(1)

    for i in range(len(k)-1, 0, -1):
        if abs(k[i] - k[i-1]) <= 1:
            continue
        elif k[i] > k[i-1]:
            k[i-1] = k[i] - 1
            for j in range(i-2, 0, -1):
                k[j] = max(k[j + 1] - 1, 0)
            break
        else:
            k[i] += 1
            k[i-1] = 0
            next_lunlun(k)
            break

    return k

i = [0]
for _ in range(k):
    next_lunlun(i)
base = 0
for num in reversed(i):
    base *= 10
    base += num
print(base)

Submission status: Wrong Answer

Solution code:

import sys
import math
import fractions
import bisect
import queue
import heapq
import collections
import itertools
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint=====================================
N, K = map(int, input().split())
N, M = map(int, input().split())
A, B = map(int, input().split())

H, W = map(int, input().split())

L, R = map(int, input().split())

1行のstring=================================
S, T = input().split()

1行の整数配列================================
P = list(map(int,input().split()))

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
D = list(map(int,input().split()))

L = list(map(int,input().split()))
R = list(map(int,input().split()))

T = list(map(int,input().split()))

改行あり整数==================================
X = []
Y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    X.append(x1)
    Y.append(y1)

A = []
for i in range(N):
    a=int(input())
    A.append(a)

Pair = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    Pair.append((x1, y1))
    
2次元整数配列=====================================
A = []
for i in range(N):
    tmp = list(map(int,input().split()))
    A.append(tmp)


N行M列の初期化====================================
dp = [[VAL] * RETU for i in range(GYO)]

'''


K = int(input())

runrun = []
runrun.append([1, 2, 3, 4, 5, 6, 7, 8, 9])


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


keta = 0
for i in range(1, 20):
    max = 9*pow(3, i-1)

    if max>=K:
        keta = i
        break

for i in range(2, keta+2):
    temp = []
    for j in range(len(runrun[i-2])):

        last = runrun[i-2][j] % 10

        tugi = (last+11) % 10
        same = last
        mae = (last+9) % 10

        temp.append(runrun[i-2][j]*10 + tugi)
        temp.append(runrun[i-2][j]*10 + same)
        temp.append(runrun[i-2][j]*10 + mae)

    runrun.append(temp)

sum_size = 0
nokori  =0
for i in range(100):
    sum_size+=len(runrun[i])
    if sum_size >= K:
        keta = i
        nokori = K- sum_size+len(runrun[i])
        break

runrun[keta].sort()

print(runrun[keta][nokori-1])

Submission status: Wrong Answer

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

    if K<10:
        ans = K
    else:
        cnt = 9
        n =10
        while True:
            ns = str(n)
            for i in range(len(ns)-1):
                if abs(int(ns[i])-int(ns[i+1])) > 1 :break
            else:
                cnt += 1
                print(cnt,n)
                if K==cnt:
                    ans = n
                    break
            n += 1
    print(ans)

    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import json
k = int(input())
# 1
# 2
# 3
# 10

# assume_valid
# list of num ??
def next_lunlun(k):
    k[0] += 1
    for i in range(len(k) - 1):
        if k[i] < 10:
            break
        k[i] -= 10
        k[i+1] += 1

    if k[-1] >= 10:
        k[-1] -= 10
        k.append(1)

    for i in range(len(k)-1, 0, -1):
        if abs(k[i] - k[i-1]) <= 1:
            continue
        elif k[i] > k[i-1]:
            k[i-1] = k[i] - 1
            for j in range(i-2, 0, -1):
                k[j] = max(k[j + 1] - 1, 0)
            break
        else:
            k[i] += 1
            k[i-1] = 0
            next_lunlun(k)
            break

    return k

i = [0]
for _ in range(k):
    next_lunlun(i)
base = 0
for num in i:
    base *= 10
    base += num
print(base)

Submission status: Wrong Answer

Solution code:
import sys

k = int(input())

counter = 13
if k < 13 :
    print(k)
else :
    for i in range(13, k**3) :
        counter += 1
        nums = list(map(int, list(str(i))))
        for j in range(0, len(nums)-1) :
            if abs(nums[j] - nums[j+1]) > 1 :
                counter -= 1
                break
        if counter == k :
            print(i+1)
            sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

K=int(input())
c=9
cb=0
r_list=[1,2,3,4,5,6,7,8,9]
while(c<K):
    tmp=[]
    for i in r_list:
        if(i%10==0):
            tmp.append(i*10)
            tmp.append(i*10+1)
        if(i%10==9):
            tmp.append(i*10+8)
            tmp.append(i*10+9)
        else:
            tmp.append(i*10+i%10-1)
            tmp.append(i*10+i%10)
            tmp.append(i*10+i%10+1)
    cb=c
    r_list=tmp
    c+=len(r_list)

    
r_list.sort()
ans=r_list[K-cb-1]
print(ans)

Submission status: Wrong Answer

Solution code:
K = int(input())
DP = [[0 for _ in range(10)] for _ in range(11)]
for i in range(10):
    DP[0][i] = 1
for i in range(10):
    for j in range(10):
        if j != 0:
            DP[i + 1][j - 1] += DP[i][j]
        if j != 9:
            DP[i + 1][j + 1] += DP[i][j]
        DP[i + 1][j] += DP[i][j]
SDP = [0 for _ in range(11)]
for i in range(11):
    for j in range(1, 10):
        SDP[i] += DP[i][j]


def hantei(N):
    global K, DP
    S = str(N)
    D = len(S)
    res = 0
    for i in range(D - 1):
        res += SDP[i]
    for i in range(1, int(S[0])):
        res += DP[D - 1][i]
    tres = 0
    for i in range(D - 1):
        if int(S[i + 1]) < int(S[i]) - 1:
            tres = 0
            break
        elif int(S[i + 1]) == int(S[i]) - 1:
            if i == D - 2:
                res += 1
        elif int(S[i + 1]) == int(S[i]):
            tres += DP[D - 2 - i][int(S[i]) - 1]
            if i == D - 2:
                res += 1
        elif int(S[i + 1]) == int(S[i]) + 1:
            tres += DP[D - 2 - i][int(S[i]) - 1]
            tres += DP[D - 2 - i][int(S[i])]
            if i == D - 2:
                res += 1
        elif int(S[i + 1]) > int(S[i]) + 1:
            tres += DP[D - 2 - i][int(S[i]) - 1]
            tres += DP[D - 2 - i][int(S[i])]
            tres += DP[D - 2 - i][int(S[i]) + 1]

    res += tres
    if res >= K:
        return True
    return False


## ある値以上であれば条件を満たす場合の「ある値」を求める。
## ある条件を満たす最小の値を求める。
def nibun(l, r):
    if r == l:
        return l
    f = (l + r) // 2
    if hantei(f):
        return nibun(l, f)
    else:
        return nibun(f + 1, r)


print(nibun(0, 3234566670))

Submission status: Wrong Answer

Solution code:
from heapq import heappop, heappush, heapify
K = int(input())

que = list(range(1, 10))
V = set()
heapify(que)

while K >= 1:
    top = heappop(que)
    if top in V:
        continue
    V.add(top)
    K -= 1

    top = str(top)
    L = int(top[0])
    R = int(top[-1])

    for i in (L - 1, L, L + 1):
        if 1 <= i <= 9:
            heappush(que, int(str(i) + top))
    for i in (R - 1, R, R + 1):
        if 0 <= i <= 9:
            heappush(que, int(top + str(i)))

print(que[0])

Submission status: Wrong Answer

Solution code:
k = int(input())
#a,b = map(int,input().split())
#a_L = list(map(int,input().split()))
if k < 10:
    pass
    print("aaa")
    exit()


i = 10
ans = 10
while True:
    s = list(str(i))
    for j in range(len(s)-1):
        flag = True
        if abs(int(s[j])-int(s[j+1])) > 1:
            flag = False
            break
    if flag:
        ans += 1
    
    if ans==k+1:
        print(i)
        exit()
    i += 1

Submission status: Wrong Answer

Solution code:
c=0
a = int(input())
for i in range(1,100001):
    f=0
    if i>12:
        l = [int(x) for x in list(str(i))]
        for j in range(1,len(str(i))):
            if abs(l[j-1]-l[j])>1:
                f=1
    if f==0:
        c+=1
    if c==a:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
S = int(input())
if S<10:
    print(S)
else:
    number=9
    for i in range(1,2**32):
        if number==S:
            print(i-1)
            break
        s=str(i)
        a=0
        for j in range(len(s)-1):
            if abs(int(s[j])-int(s[j+1]))<=1:
                a=1
                break
        if a==1:
            number+=1

Submission status: Wrong Answer

Solution code:
k = int(input())
count = 0
for i in range(100000):
    num = i + 1
    k_list = []
    for k_i in str(num):
        k_list.append(int(k_i))
    for j, ele in enumerate(k_list):
        if j == 0:
            continue
        if abs(k_list[j - 1] - k_list[j]) > 1:
            break
    else:
        count += 1
    if count == k:
        print(num)
        break

Submission status: Wrong Answer

Solution code:
k = int(input())
#a,b = map(int,input().split())
#a_L = list(map(int,input().split()))
if k < 10:
    pass
    print("aaa")
    exit()


i = 10
ans = 10
while True:
    s = list(str(i))
    for j in range(len(s)-1):
        if abs(int(s[j])-int(s[j+1])) <= 1:
            ans += 1
            #print(s)
            break
    if ans==k+1:
        print(i)
        exit()
    i += 1

Submission status: Wrong Answer

Solution code:
K = int(input())

flags = [-1] * (10**8+7)

count = 0
now = 1
flags[0] = 1
while count != K:
    if now < 10:
        flags[now] = 1
    elif now < 100:
         if abs((now % 10) - (now // 10)) <= 1:
             flags[now] = 1
         else:
             flags[now] = 0
    else:
        if flags[int(str(now)[1:])]:
            if abs(int(str(now)[0]) - int(str(now)[1])) <= 1:
                flags[now] = 1
            else:
                flags[now] = 0
        else:
            flags[now] = 0
    if flags[now] == 1:
        count += 1
    # print('count: {}, now: {}, flag: {}'.format(count, now, flags[now]))
    now += 1

print(now - 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
    if n == K:
      print(i)
      break
  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())
dp = [['1','2','3','4','5','6','7','8','9'],[]]

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