Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-

'''
100000
99990
90000
'''

K = int(input())
# K = 100000 - K

# c = list(str(3234566667))

c = 1

for i in range(K):
    str_c = list(str(c))
    str_c = [int(i) for i in str_c][::-1]

    keta = len(str_c)
    # print(c)
    # print(str_c)

    if set(str_c) == set([9]):
        c = c + 1
        continue

    for ket in range(keta):
        
        if ket == keta - 1:
            str_c[ket] += 1

            for j in range(ket):
                # print(str_c)
                if str_c[ket - j] == 0:
                    str_c[ket - j - 1] = 0
                else:
                    str_c[ket - j - 1] = str_c[ket - j] - 1

            str_c = [str(i) for i in str_c][::-1]
            c = int(''.join(str_c))
            break

        if str_c[ket] == str_c[ket + 1] + 1:
            continue

        
        if abs(str_c[ket] - str_c[ket + 1]) <= 1:
            if str_c[ket] < 9:
                str_c[ket] += 1
                for j in range(ket):
                    if str_c[ket - j] == 0:
                        str_c[ket - j - 1] = 0
                    else:
                        str_c[ket - j - 1] = str_c[ket - j] - 1
                str_c = [str(i) for i in str_c][::-1]
                c = int(''.join(str_c))
                break


print(c)



# -*- 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('')


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

'''
100000
99990
90000
'''

K = int(input())
# K = 100000 - K

# c = list(str(3234566667))

c = 1

for i in range(K -1):
    str_c = list(str(c))
    str_c = [int(i) for i in str_c][::-1]

    keta = len(str_c)
    # print(c)
    # print(str_c)

    if set(str_c) == set([9]):
        c = c + 1
        continue

    for ket in range(keta):
        
        if ket == keta - 1:
            str_c[ket] += 1

            for j in range(ket):
                # print(str_c)
                if str_c[ket - j] == 0:
                    str_c[ket - j - 1] = 0
                else:
                    str_c[ket - j - 1] = str_c[ket - j] - 1

            str_c = [str(i) for i in str_c][::-1]
            c = int(''.join(str_c))
            break

        if str_c[ket] == str_c[ket + 1] + 1:
            continue

        
        if abs(str_c[ket] - str_c[ket + 1]) <= 1:
            if str_c[ket] < 9:
                str_c[ket] += 1
                for j in range(ket):
                    if str_c[ket - j] == 0:
                        str_c[ket - j - 1] = 0
                    else:
                        str_c[ket - j - 1] = str_c[ket - j] - 1
                str_c = [str(i) for i in str_c][::-1]
                c = int(''.join(str_c))
                break


print(c)


Verdicts: Wrong Answer

Wrong Answer

Accepted