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())
A = list(range(10))

if k <= 9:
    print(A[k])
    exit()


def is_1_keta(i):
    return len(str(i)) == 1


kouho = list(map(str, range(1, 10)))
kouho2 = list(map(str, range(1, 10)))
while True:
    ll = []
    for i in kouho:
        su = list(filter(is_1_keta, [int(i[-1]) - 1, int(i[-1]), int(i[-1]) + 1]))
        l = [f"{i}{x}" for x in su]
        A.extend(l)
        ll.extend(l)
    kouho = ll
    kouho2.extend(ll)
    if len(kouho2) > k:
        break

print(sorted(list(map(int, kouho2)))[k - 1])

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

bool lunlun(int64_t n){
  string m=to_string(n);
  bool x=true;
  for(int i=0; i<m.size()-1; i++){
    int a=m.at(i) - '0', b=m.at(i+1) - '0';
    //cout << a << ":" << b << endl;
    if(a-b==-1 || a-b==0 || a-b==1)
      x=true;
    else
      return false;
  }
  return true;
  
}


int main() {
  int k;
  cin >> k;
  int64_t num=1;
  int count=0;
  while(count<k){
    //cout << num << ":" << count << endl;
    if(lunlun(num)==true){
      //cout << "lunlun!" << endl;
      count++;
    }
    
    
    if(count==k){
      cout << num << endl;
      break;
    }else
      num++;
  }
}

Submission status: Runtime Error

Solution code:
k=int(input())
A=[[1,1,1,1,1,1,1,1,1,1]]
for i in range(9):
    Ai=[]
    Ai.append(A[i][0]+A[i][1])
    for j in range(8):
        Ai.append(A[i][j]+A[i][j+1]+A[i][j+2])
    Ai.append(A[i][7]+A[i][8])
    A.append(Ai)
c=[]
for i in range(len(A)):
    c.append(sum(A[i][1:10]))
l=1 #length of number
while k>c[l-1]:
    k=k-c[l-1]
    l+=1
seq=[]

n=1 
while k>A[l-1][n]:
    k=k-A[l-1][n]
    n+=1
seq.append(n)#head number

for i in range(l-1):
    if seq[i]==0:
        j=0
        while k>A[l-2-i][j]:
            k=k-A[l-2-i][j]
            j+=1
        seq.append(j)
    else:
        j=seq[i]-1
        while k>A[l-2-i][j]:
            k=k-A[l-2-i][j]
            j+=1        
        seq.append(j)

for i in range(len(seq)):
    print(seq[i],end="")

Submission status: Runtime Error

Solution code:
i = int(input())
p = 11
count = 10
if i < 11:
  print(i)
else:
  i = 1 - 10
  while i != count:
    x = p.split()
    l = len(x) - 1
    j = 0
    for f range(l):
      if abs(int(x[f]) - int(x[f+1])) > 1:
        j = 1
    if j == 0:
      count += 1
  print(count)

Submission status: Runtime Error

Solution code:
k=int(input())
num_digit=[0]*10 #num_digit[i]は10^i以下のルンルン数の個数
num_digit[0]=9
tmp=[[0]*10 for i in range(10)] #tmp[i][j]はi+1桁で最高位jの個数
tmp[0]=[0,1,1,1,1,1,1,1,1,1]
for i in range(1,9):
  num_digit[i]=num_digit[i-1]
  tmp[i][0]=tmp[i-1][0]+tmp[i-1][1]
  num_digit[i]+=tmp[i][0]
  for j in range(1,9):
    tmp[i][j]=tmp[i-1][j-1]+tmp[i-1][j]+tmp[i-1][j+1]
    num_digit[i]+=tmp[i][j]
  tmp[i][9]=tmp[i-1][8]+tmp[i-1][9]
  num_digit[i]+=tmp[i][9]
  
def lnln(n):
  ans=0
  d=0
  tmp_n=n
  while num_digit[d]<n:
    d+=1
  tmp_n-=num_digit[d-1]
  while tmp[d][ans]<tmp_n:
    tmp_n-=tmp[d][ans]
    ans+=1
  ans*=10**d
  if n>9:
    ans+=lnln(tmp_n)
  return ans

print(lnln(k))

Submission status: Runtime Error

Solution code:
k = input()
k = int(k)

if 1 <= k and k <= 9:
    print(k)
elif 10 <= k and k <= 35:
    temp = k-9
    q = temp // 3
    p = temp % 3
    
    s = ""
    s = s + str(q)
    if p == 0:
        s = s + str(q+1)
    elif p == 1:
        s = s + str(q)
    elif p == 2:
        s = s + str(q-1)
print(s)

Submission status: Runtime Error

Solution code:
m=int(input())


k = 100000
l=[]

for i in range(k):
    n=list(str(i))
    keta=len(str(i))
    if keta==1:
        l.append(i)
    elif keta==2:
        if abs(int(n[0])-int(n[1]))==1:
            l.append(i)
    elif keta==3:
        if abs(int(n[0])-int(n[1]))==1 and abs(int(n[1])-int(n[2]))==1 :
            l.append(i)
    elif keta==4:
        if abs(int(n[0])-int(n[1]))==1 and abs(int(n[1])-int(n[2]))==1 and abs(int(n[2])-int(n[3]))==1 :
            l.append(i)
    elif keta==5:
        if abs(int(n[0])-int(n[1]))==1 and abs(int(n[1])-int(n[2]))==1 and abs(int(n[2])-int(n[3]))==1 and abs(int(n[3])-int(n[4]))==1 :
            l.append(i)
    else:
        l.append(i)

print(l[m-1])

Submission status: Runtime Error

Solution code:
N, count, i, lists = input(), 0, 0, []
while len(lists) != N:
    for i in range(9, 10000000):
        i = str(i)
            for x in range(len(i) - 1):
                if abs(i[x] - i[x + 1]) == 1:
                    count += 1
            if count == (len(i) - 1):
                    lists.append(i)
print(lists[len(lists) - 9])