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: Runtime Error

Solution code:
K = int(input())
lun = [1, 2, 3, 4, 5, 6, 7, 8, 9]
cnt = 0

while(len(lun) < K):
  target = lun[cnt]
  num = target % 10
  print(lun,target,num)
  if num != 0:
      lun.append(target * 10 + num - 1)
  lun.append(target * 10 + num)
  if num != 9:
      lun.append(target * 10 + num + 1)
  cnt += 1

print(lun[K-1])

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
K = int(input())
RUN = {
    0:[0, 1],
    1:[0, 1, 2],
    2:[1, 2, 3],
    3:[2, 3, 4],
    4:[3, 4, 5],
    5:[4, 5, 6],
    6:[5, 6, 7],
    7:[6, 7, 8],
    8:[7, 8, 9],
    9:[8, 9]
}
cnt = 0

def dfs(i, s, p):
    if i == 0:
        cnt = cnt + 1
        if cnt == K:
            print(s)
            exit()
    if s == 0:
        for ii in range(10):
            dfs(i-1, s+ii*10**(i-1), ii)
    else:
        for ii in RUN[p]:
            dfs(i-1, s+ii*10**(i-1), ii)

dfs(10, 0, 0)

Submission status: Runtime Error

Solution code:
k = int(input())
x =[int(0)]*(k*k)
count=0
mem=0
for a in range(k*k):
    n = str(a)
    if(len(n))==1:
        x[int(n)]=1
        mem=int(n)
        count+=1
    elif x[int(n[:-1])]==1 and abs(int(n[-1])-int(n[-2]))<2:
        x[int(n)]=1
        mem=int(n)
        count+=1
    if count>k:
        break
print(mem)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque

def get_digits(i):
    last_digit = int(str(i)[-1])
    if last_digit in list(range(1,9)):
        return [last_digit-1, last_digit, last_digit+1]
    elif last_digit == 0:
        return [last_digit, last_digit+1]
    elif last_digit == 9:
        return [last_digit-1, last_digit]

def solve(K: int):
    deq1 = deque()
    deq2 = deque()
    lunlun_list = []

    for i in range(1,10):
        deq1.append(i)
        lunlun_list.append(i)

    while  len(lunlun_list) <= 10 ** 5:
        num = deq1.popleft()
        digits = get_digits(num)
        for new_digit in digits:
            new_num = int(str(num)+str(new_digit))
            lunlun_list.append(new_num)
            deq2.append(new_num)

        if len(deq1) == 0:
            deq1 = deq2.copy()
            deq2 = deque()

    print(lunlun_list[K-1])


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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
K = int(input())

count = 0
num = 0
while count < K:
    num += 1
    flag = True
    num_str = str(num)
    if len(num_str) >= 2:
        for i in range(len(num_str) - 1):
            if ads(int(num_str[i]) - int(num_str[i + 1])) > 1:
                flag = False

    if flag:
        count += 1

print(num)

Submission status: Runtime Error

Solution code:
k= int(input())
runrun = [1,2,3,4,5,6,7,8,9]
for i in range(10, 1000000):
    si = str(i)
    lsi = len(si)
    t =False
    for i in range(lsi-1):
        if abs(int(si[i]) - int(si[i+1])) <= 1:
            t = True
        else:
            t = False
            break
    if t:
        runrun.append(int(si))
print(runrun[k-1])