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: Time Limit Exceeded

Solution code:
def kansu(i):



    s = list(str(i))



    smozi = ""

    if abs(int(s[-1]) - int(s[-2])) < 2:

        return 0

    else:

        s[-2] = str(int(s[-2]) + 1)

        flag = True

        while flag:

            a = -2

            if abs(a) == len(s) or abs(int(s[a - 1]) - int(s[a])) < 2:

                if abs(a) == len(s):

                    a += 1

                s[a - 1] = str(int(s[a - 1]) + 1)

                flag == False

                w = 1

                for i in range(a + 1 , -2):

                    s[i] = str(int(s[a - 1]) - w)

                    w += 1

            else:

                a -= 1



        for i in range(len(s)):

            smozi += str(s[i])



        return int(smozi)



def d161(k):



    ans = 10

    count = 10



    if k < 10:

        return k



    while count < k:

        ans += 1

        reans = kansu(ans)



        if reans == 0:

            count += 1

        else:

            ans = reans



    return ans



def main():

    k = int(input())

    print(d161(k))

if __name__ == '__main__':

    main()

Submission status: Time Limit Exceeded

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

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%MOD
            break
if k <= 9:
    print(k)
else:
    print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

num = 0
for i in range(1, 100000000000):
  cnt = 0
  moji = str(i)
#  print(moji)
  for j in range(len(moji)-1):
    first = int(moji[j])
    second = int(moji[j+1])
    if abs(first - second) <= 1:   
      cnt += 1
    else:
      continue
  if cnt == len(moji)-1:
    num +=1
#    print('num{}'.format(num))
  if num == k:
    break
print(int(moji))

Submission status: Time Limit Exceeded

Solution code:
K=int(input()) 
num=0
a=1
cnt=0
while True:
  num+=1
  s=str(num)
  l=len(s)
  array=list(map(int,s))
  if l==1:
    a=num
    cnt+=1
  elif all(abs(array[j+1]-array[j])<=1 for j in range(l-1)):
    a=num
    cnt+=1
  if cnt==K:
    break
print(a)

Submission status: Time Limit Exceeded

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=[]
while True:
    if runrunConfirm(number):
        runrunlist.append(number)
    if len(runrunlist)==K:
        print(runrunlist[K-1])
        exit()
    number+=1

Submission status: Time Limit Exceeded

Solution code:
def checkLunlun(n):
  check = 0
  s=str(n)
  for i in range(len(s)-1):
    # print(i)
    if not abs(int(s[i]) - int(str(s[i+1]))) <= 1:
      check += 1
  if check == 0:
    return True
  else:
    return False

K = int(input())
n = 0
count = 0
while not count == K:
  n+=1
  if checkLunlun(n):
    count += 1
print(n)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

def is_runrun(x):
    s = str(x)
    b = True
    if len(s) > 1:
        for i in range(len(s)-1):
            if abs(int(s[i]) - int(s[i+1])) > 1:
                b = False
                break
    return b

x = 0
count = 1
while(count < k+1):
    x = x + 1
    if is_runrun(x):
        count = count + 1

print(x)