input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
import sys
import heapq
def input(): return sys.stdin.readline().rstrip()
def main():
K = int(eval(input()))
q = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapq.heapify(q)
while len(q) < K:
K -= len(q)
new_q = []
for i in q:
d1 = int(str(i)[-1])
if d1 > 0:... | import sys
import heapq
def input(): return sys.stdin.readline().rstrip()
def main():
K = int(eval(input()))
q = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapq.heapify(q)
while len(q) < K:
K -= len(q)
new_q = []
for i in q:
d1 = i % 10
if d1 > 0:
... | p02720 |
from collections import deque
k = int(eval(input()))
L = [1,2,3,4,5,6,7,8,9]
L = deque(L)
i = 0
while i < k:
if int(str(L[i])[-1]) == 0:
n2 = L[i]*10 + L[i]%10
n3 = L[i]*10 + L[i]%10 +1
L.append(n2)
L.append(n3)
elif 1 <= int(str(L[i])[-1]) <= 8:
n1 = L[i]*10 ... | k = int(eval(input()))
L = []
def lunlun(d,v,L):
L.append(v)
if d == 10:
return
for i in range(-1,2):
t = v%10 + i
#print(v)
if 0 <= t <=9:
lunlun(d+1,v*10+t,L)
#lunlun(1,1,L)
for v in range(1,10):
lunlun(1,v,L)
print((sorted(L)[k-1])) | p02720 |
k = int(eval(input()))
L = []
def lunlun(d,v,L):
L.append(v)
if d == 10:
return
for i in range(-1,2):
t = v%10 + i
#print(v)
if 0 <= t <=9:
lunlun(d+1,v*10+t,L)
#lunlun(1,1,L)
for v in range(1,10):
lunlun(1,v,L)
print((sorted(L)[k-1])) | from collections import deque
K = int(eval(input()))
q = [1, 2, 3, 4, 5, 6, 7, 8, 9]
q = deque(q)
def next_n(n):
if n == 0:
return [0, 1]
elif n == 9:
return [8, 9]
else:
return [n-1, n, n+1]
for _ in range(K-1):
now = q.popleft()
for next_ in next_n(now%10... | p02720 |
import sys
from string import digits
k = int(sys.stdin.readline().rstrip())
def main():
if k <= 9:
print(k)
return
res = list(digits[1:])
r = k - 9
nex = []
while True:
for n in res:
o = ord(n[-1])
for i in range(-1, 2):
... | import sys
k = int(sys.stdin.readline().rstrip())
def main(k):
if k <= 9:
print(k)
return
res = list(range(1, 10))
k -= 9
while True:
nex = []
for n in res:
r = n % 10
n *= 10
for i in range(-1, 2):
if ... | p02720 |
import heapq
K =int(eval(input()))
pque = []
for i in range(1, 10):
heapq.heappush(pque, i)
for i in range(K):
tmp = heapq.heappop(pque)
if tmp % 10 == 0:
heapq.heappush(pque, tmp * 10)
heapq.heappush(pque, tmp * 10 + 1)
elif tmp % 10 == 9:
heapq.heappush(pque, t... | K = int(eval(input()))
if K <= 9:
print (K)
exit()
lst = [[1] * 11 for _ in range(2)]
lst_append = lst.append
lst[0][10] = 0
lst[1][0] = 0
lst[1][10] = 0
now = 9
p = 0
flag = 0
while True:
if p == 0:
lst[flag + 1][0] = lst[flag][0] + lst[flag][1]
p += 1
continue... | p02720 |
import queue
K = int(eval(input()))
q = queue.Queue()
for i in range(1,10):
q.put(i)
for i in range(K):
x = q.get()
a = x%10
if a !=0:
q.put(10*x +a -1)
q.put(10*x +a )
if a != 9:
q.put(10*x +a +1)
print(x) | def main():
import sys
def input(): return sys.stdin.readline().rstrip()
k = int(eval(input()))
from collections import deque
que = deque(list(range(1, 10)))
for i in range(k):
now = que.popleft()
r = now%10
nx = now*10
if r == 0:
for j in [... | p02720 |
k = int(eval(input()))
lunlun = []
def dfs(A):
if len(A) > 10:
return
else:
num = A[-1]
lunlun.append(int("".join(A)))
if num == "0":
for i in range(0, 2):
A.append(str(i))
dfs(A)
A.pop()
elif num =... | k = int(eval(input()))
lunlun = []
def dfs(A):
if len(A) > 10:
return
else:
num = int(A[-1])
lunlun.append(int("".join(A)))
if num == 0:
for i in range(0, 2):
A.append(str(i))
dfs(A)
A.pop()
elif nu... | p02720 |
k = int(eval(input()))
def hantei(n):
string = str(n)
length = len(string)
ret = True
for i in range(length-1):
if abs(int(string[i]) - int(string[i+1])) > 1:
ret = False
break
return ret
lst = [i for i in range(10)]
dic = {}
dic[1] = lst.copy()
keta ... | from collections import deque
k = int(eval(input()))
if 1 <= k and k <= 9:
print(k)
exit()
d = deque([i for i in range(1, 10)])
k -= 9
while k > 0:
num = d.popleft()
if num % 10 != 0:
new = 10*num + (num%10) - 1
d.append(new)
k -= 1
if k == 0: break
... | p02720 |
from collections import deque
k = int(eval(input()))
if 1 <= k and k <= 9:
print(k)
exit()
d = deque([i for i in range(1, 10)])
k -= 9
while k > 0:
num = d.popleft()
if num % 10 != 0:
new = 10*num + (num%10) - 1
d.append(new)
k -= 1
if k == 0: break
... | k = int(eval(input()))
if k <= 9:
print(k)
k -= 9
lst = list(range(1, 10))
while k > 0:
new = []
for num in lst:
amari = num % 10
if amari == 0:
new.append(num*10)
new.append(num*10+1)
elif amari == 9:
new.append(num*10+8)
... | p02720 |
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *
class Scanner():
... | # -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal
... | p02720 |
from queue import Queue
k = int(eval(input()))
q = Queue()
Lunlun = []
for i in range(1, 10):
q.put(i)
while True:
if len(Lunlun) >= 10**5:
break
now = q.get()
Lunlun.append(now)
for i in range(-1, 2):
if (now % 10) + i < 0 or 9 < (now % 10) + i:
continue
... | import collections
# from queue import Queue
k = int(eval(input()))
q = collections.deque()
Lunlun = []
for i in range(1, 10):
q.append(i)
while True:
if len(Lunlun) >= 10**5:
break
now = q.popleft()
Lunlun.append(now)
for i in range(-1, 2):
if (now % 10) + i < 0 or 9 < ... | p02720 |
import queue
N = int(eval(input()))
q = queue.Queue()
for i in range(1, 10):
q.put(i)
ans = 0
for i in range(N):
ans = q.get()
m = ans % 10
if ans % 10 != 0:
q.put(ans * 10 + m - 1)
q.put(ans * 10 + m)
if ans % 10 != 9:
q.put(ans * 10 + m + 1)
print(ans) | import sys
sys.setrecursionlimit(10**6)
def dfs(n):
if n > 3234566667:
return
ans.append(n)
if n % 10 != 0:
dfs(n * 10 + (n % 10) - 1)
dfs(n * 10 + (n % 10))
if n % 10 != 9:
dfs(n * 10 + (n % 10) + 1)
N = int(eval(input()))
ans = []
for i in range(1, 10):
... | p02720 |
def main():
K = int(eval(input()))
ans = set()
def rec(S):
if 3234566667 < int(S):
return
c = S[-1]
d = int(c)
for plus in range(d-1, d+2):
if plus < 0:
continue
ans.add(int(S+str(plus)))
rec(S+str(... | def main():
K = int(eval(input()))
LL = set()
def dfs(s):
if 3234566667 < int(s):
return
c = int(s[-1])
for p in range(-1, 2):
if c+p < 0 or 9 < c+p:
continue
LL.add(int(s+str(c+p)))
dfs(s+str(c+p))
f... | p02720 |
import sys
k = int(eval(input()))
if k <= 9:
print(k)
sys.exit()
def judge(s):
for i in range(1,len(s)):
if abs(int(s[i-1]) - int(s[i])) > 1:
return 0
return 1
q = ['1','2','3','4','5','6','7','8','9']
cnt = 9
cond = False
while True:
cp = q.pop(0)
digit = int(cp[-1])
for d in range(-1... | import sys
from collections import deque
K = int(eval(input()))
if K <= 9:
print(K)
sys.exit()
q = deque(['1', '2','3','4','5','6','7','8','9'])
cnt = 0
while True:
cp = q.popleft()
cnt += 1
if cnt == K:
ans = int(cp)
break
r = int(cp[-1])
for d in [-1,0,1]:
dd = r + d
if 0 <= dd < 10:
... | p02720 |
from collections import deque
K = int(eval(input()))
Queue = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in range(K):
x = Queue[0]
Queue.popleft()
oneplace = x % 10
#(1の位の数)-1を付け加えた数を入れる
if oneplace == 0: #xの1の位が0
pass
else: #xの1の位が0でない
enqueue = x * 10 + (oneplace ... | k = int(eval(input()))
B = [1, 2, 3, 4, 5, 6, 7, 8, 9] #Before list
while len(B) < k:
k -= len(B)
#次の桁に更新
def update_next_digit(B:list)->list:
N = [] #New list
for i in range(len(B)):
op = B[i] % 10 #one place
for j in [-1, 0, 1]:
if 0... | p02720 |
def main():
K = int(eval(input()))
lunlun = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
start1 = ["1"]
start2 = ["2"]
start3 = ["3"]
start4 = ["4"]
start5 = ["5"]
start6 = ["6"]
start7 = ["7"]
start8 = ["8"]
start9 = ["9"]
while len(lunlun) < 10 ** 5:... | from collections import deque
K = int(eval(input()))
queue = deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"])
lunlun = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
while len(queue) < 10 ** 5:
n_str = queue.popleft()
last_c = n_str[len(n_str) - 1]
if last_c == "0":
queue.append(n_str... | p02720 |
K = int(input())
N = [0]
for _ in range(K):
i = 0
while i < len(N) and N[i] == 9:
i += 1
while i+1 < len(N) and N[i] == N[i+1]+1:
i += 1
if i == len(N):
N = [0]*len(N) + [1]
else:
N[i] += 1
i -= 1
while i >= 0:
N[i] = max(... | from collections import deque
K = int(eval(input()))
q = deque(list(range(1,10)))
for _ in range(K):
x = q.popleft()
r = x%10
if r == 0:
q.append(x*10)
q.append(x*10+1)
elif r == 9:
q.append(x*10+8)
q.append(x*10+9)
else:
q.append(x*10+r-1... | p02720 |
import copy
K = int(eval(input()))
ans, nex = [i for i in range(1, 10)], [i for i in range(1, 10)]
for i in range(10):
pre, nex = copy.deepcopy(nex), []
for p in pre:
if p % 10 != 0:
ans.append(p * 10 + p % 10 - 1)
nex.append(p * 10 + p % 10 - 1)
ans.append(p * 1... | from collections import deque
d = deque([9, 8, 7, 6, 5, 4, 3, 2, 1])
K = int(eval(input()))
for _ in range(K - 1):
i = d.pop()
if i % 10 != 0:
d.appendleft(i * 10 + i % 10 - 1)
d.appendleft(i * 10 + i % 10)
if i % 10 != 9:
d.appendleft(i * 10 + i % 10 + 1)
print((d.pop()))
| p02720 |
def pat(K,count,keta,num):
#print(str(num)+":"+str(count)+":"+str(keta))
if count == -1:
return -1
elif keta == 1:
if count == K-1:
print(num)
return count + 1
else:
return (count+1)
else:
if (int(num[-1])) -1 >= 0:
... | def pat(K,count,keta,num):
#print(str(num)+":"+str(count)+":"+str(keta))
if count == -1:
return -1
elif keta == 1:
if count == K-1:
print(num)
return -1
else:
return (count+1)
else:
if (int(num[-1])) -1 >= 0:
cou... | p02720 |
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, produc... | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, produc... | p02720 |
import sys
def input():
return sys.stdin.readline().strip()
def main():
K = int(eval(input()))
ans = list("123456789")
tmp = ans.copy()
while True:
tmp2 = []
for t in tmp:
for i in range(int(t[-1]) - 1, int(t[-1]) + 2):
if 0 <= i < 10:
... | import collections
import sys
def input():
return sys.stdin.readline().strip()
def bfs(K):
q = collections.deque(list("123456789"))
ans = list("123456789")
while len(ans) < K:
n = q.popleft()
for i in range(int(n[-1]) - 1, int(n[-1]) + 2):
if 0 <= i < 10:
... | p02720 |
from collections import deque
k = int(eval(input()))
lunlun = deque([i for i in range(9, 0, -1)])
for i in range(k):
x = lunlun.pop()
if i == k - 1:
print(x)
next_lunlun = 10*x + (x % 10)
if x % 10 != 0:
lunlun.appendleft(next_lunlun - 1)
lunlun.appendleft(next_lunlun)
... | from collections import deque
k = int(eval(input()))
lunlun = deque(list(range(1, 10)))
for i in range(k):
x = lunlun.popleft()
next = 10*x + (x % 10)
if x % 10 != 0:
lunlun.append(next - 1)
lunlun.append(next)
if x % 10 != 9:
lunlun.append(next + 1)
print(x) | p02720 |
K = int(eval(input()))
def is_lunlun(i):
result = -1
n = [ord(c) -48 for c in str(i)]
for j in range(len(n) - 1):
if abs(n[j] - n[j + 1]) <= 1:
continue
if n[j] < n[j + 1]:
for k in range(j + 1, len(n)):
n[k] = 0
result = int(''... | K = int(eval(input()))
def is_lunlun(i):
result = -1
n = [ord(c) - 48 for c in str(i)]
for j in range(len(n) - 1):
if abs(n[j] - n[j + 1]) <= 1:
continue
if n[j] < n[j + 1]:
for k in range(j + 1, len(n)):
n[k] = max(n[k - 1] - 1, 0)
... | p02720 |
K = int(eval(input()))
A = [1,2,3,4,5,6,7,8,9]
for i in range(len(A)):
if A[i] != 9:
for j in range(-1,2):
a = int(str(A[i]) + str(A[i]+j))
A.append(a)
else:
A.append(98)
A.append(99)
A.append(100)
A.append(101)
L1 = len(A.copy())
for i in range(10,L1... | K = int(eval(input()))
A = [1,2,3,4,5,6,7,8,9]
for i in range(len(A)):
if A[i] != 9:
for j in range(-1,2):
a = int(str(A[i]) + str(A[i]+j))
A.append(a)
else:
A.append(98)
A.append(99)
A.append(100)
A.append(101)
L1 = len(A.copy())
for i in range(10,L1... | p02720 |
K = int(eval(input()))
A = [1,2,3,4,5,6,7,8,9]
for i in range(len(A)):
if A[i] != 9:
for j in range(-1,2):
a = int(str(A[i]) + str(A[i]+j))
A.append(a)
else:
A.append(98)
A.append(99)
A.append(100)
A.append(101)
L1 = len(A.copy())
for i in range(10, L... | K = int(eval(input()))
A = [1,2,3,4,5,6,7,8,9]
for i in range(len(A)):
if A[i] != 9:
for j in range(-1,2):
a = int(str(A[i]) + str(A[i]+j))
A.append(a)
else:
A.append(98)
A.append(99)
A.append(100)
A.append(101)
L1 = 10
L2 = len(A.copy())
for i in ra... | p02720 |
from queue import Queue
k = int(eval(input()))
q = Queue()
for i in range(1, 10):
q.put(i)
for _ in range(k):
x = q.get()
if x % 10 != 0:
q.put(x*10 + x%10 - 1)
q.put(x*10 + x%10)
if x % 10 != 9:
q.put(x*10 + x%10 + 1)
print(x)
| from collections import deque
k = int(eval(input()))
q = deque(list(range(1, 10)))
for _ in range(k):
x = q.popleft()
if x % 10 != 0:
q.append(x*10 + x%10 - 1)
q.append(x*10 + x%10)
if x % 10 != 9:
q.append(x*10 + x%10 + 1)
print(x) | p02720 |
# Problem D - Lunlun Number
# input
K = int(eval(input()))
# initialization
num_queue = []
k = 1
# count
while True:
if k>=1 and k<=9: # 1桁の場合
num_queue.append(k)
k += 1
else: # 2桁以降の場合
min_num = str(num_queue.pop(0))
keta_1 = int(min_num[-1])
if keta_... | # Problem D - Lunlun Number
from collections import deque
# input
K = int(eval(input()))
# initialization
num_queue = deque()
k = 1
# count
while True:
if k>=1 and k<=9:
num_queue.append(k)
k += 1
else:
num = str(num_queue.popleft())
num_str = int(num[-1])
... | p02720 |
def dfs(d, r):
global l
if d == 11:
return
l.append(int(r))
for i in range(-1, 2):
tmp = int(r[-1]) + i
if 0 <= tmp <= 9:
dfs(d + 1, r + str(tmp))
k = int(eval(input()))
l = []
for i in range(1, 10):
dfs(0, str(i))
print((sorted(l)[k - 1])) | def dfs(d, r):
global l
if d == 11:
return
l.append(int(r))
for i in range(-1, 2):
tmp = int(r[-1]) + i
if 0 <= tmp <= 9:
dfs(d + 1, r + str(tmp))
k = int(eval(input()))
l = []
for i in range(1, 10):
dfs(1, str(i))
print((sorted(l)[k - 1])) | p02720 |
K = int(eval(input()))
lunlun_number_list = []
def dfs(N):
lunlun_number_list.append(N)
if len(str(N)) > 10:
return
now_int = int(str(N)[-1])
if now_int == 0:
for i in range(2):
dfs(N*10 + i)
elif now_int == 9:
for i in range(8, 10, 1):
... | import collections
K = int(eval(input()))
que = collections.deque()
for i in range(1, 10, 1):
que.append(i)
cnt = 0
for i in range(K):
x = que.popleft()
cnt += 1
if cnt == K:
print(x)
exit()
if x%10 == 0:
que.append(10*x+0)
que.append(10*x+1)
elif... | p02720 |
import os
import sys
from functools import lru_cache
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
def is_ok(n):
s = str(n)
ok = True
for a, b in zip(s, s[1:]):
... | import os
import sys
from collections import deque
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
# 解説
K = int(sys.stdin.buffer.readline())
que = deque(list(map(str, list(range(1, 10)))))... | p02720 |
K=int(eval(input()))
A=[1,2,3,4,5,6,7,8,9]+[0]*10*K
i=9
j=0
while i<K:
if A[j]%10!=0 and A[j]%10!=9:
A[i]=10*A[j]+A[j]%10-1;i+=1
A[i]=10*A[j]+A[j]%10;i+=1
A[i]=10*A[j]+A[j]%10+1;i+=1
elif A[j]%10==0:
A[i]=10*A[j]+A[j]%10;i+=1
A[i]=10*A[j]+A[j]%10+1;i+=1
el... | K=int(eval(input()))
A=[1,2,3,4,5,6,7,8,9]+[0]*K
i=9
j=0
while i<K:
if A[j]%10!=0 and A[j]%10!=9:
A[i]=10*A[j]+A[j]%10-1;i+=1
A[i]=10*A[j]+A[j]%10;i+=1
A[i]=10*A[j]+A[j]%10+1;i+=1
elif A[j]%10==0:
A[i]=10*A[j]+A[j]%10;i+=1
A[i]=10*A[j]+A[j]%10+1;i+=1
else:... | p02720 |
from heapq import heappop, heappush, heapify
K = int(eval(input()))
M = K
que = list(range(1, 10))
V = set()
heapify(que)
while M + 100 >= 0:
top = heappop(que)
if top in V:
continue
V.add(top)
M -= 1
top = str(top)
L = int(top[0])
R = int(top[-1])
for i in... | from collections import deque
K = int(eval(input()))
que = deque(list(map(str, list(range(1, 10)))))
while K > 1:
n = que.popleft()
K -= 1
R = int(n[-1])
for r in (R - 1, R, R + 1):
if 0 <= r <= 9:
que.append(n + str(r))
print((que[0]))
| p02720 |
from collections import deque
K = int(eval(input()))
que = deque(list(map(str, list(range(1, 10)))))
while K > 1:
n = que.popleft()
K -= 1
R = int(n[-1])
for r in (R - 1, R, R + 1):
if 0 <= r <= 9:
que.append(n + str(r))
print((que[0]))
| from collections import deque
K = int(eval(input()))
que = deque([i for i in range(1, 10)])
ans = []
while len(ans) <= K + 10:
now = que.popleft()
ans.append(now)
b = now % 10
for i in range(max(0, b - 1), min(10, b + 2)):
que.append(now * 10 + i)
ans.sort()
print((ans[K - 1])... | p02720 |
from collections import deque
k=int(eval(input()))
num=[]
def dfs(lun):
#print(lun)
num.append(lun)
if lun>3234566667:
return
now=lun%10
for i in [-1,0,1]:
if 0<=now+i<=9:
dfs(lun*10+now+i)
for i in range(1,10):
dfs(i)
num.sort()
print((num[k-1]))
#print(num[0:k])
| from collections import deque
k=int(eval(input()))
d=deque([1,2,3,4,5,6,7,8,9])
num=[1,2,3,4,5,6,7,8,9]
while d:
now=d.popleft()
hitoketa=now%10
for i in [-1,0,1]:
if 0<=hitoketa+i<=9:
nxt=now*10+hitoketa+i
if nxt<=3234566667:
#print(nxt)
num.append(nxt)
d.appe... | p02720 |
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
K = int(eval(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, cnt):
... | import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
K = int(eval(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 = -1
def dfs(i, s, p, cnt):
... | p02720 |
n=int(eval(input()))
query = [1, 2, 3, 4, 5, 6, 7, 8, 9]
if n <= 9:
print(n)
else:
count = 9
while count<=n:
i = query.pop(0)
if i%10-1>=0:
query.append(i*10+(i%10-1))
count += 1
if count == n:
print((i*10+(i%10-1)))
... | from collections import deque
n=int(eval(input()))
if n < 10:
print(n)
else:
check_box = deque([1,2,3,4,5,6,7,8,9])
check_num = 9
while True:
add_num = check_box.popleft()
add_num = str(add_num)
if int(add_num[-1]) - 1 >= 0:
check_box.append(int(add_n... | p02720 |
from collections import deque
def main():
k = int(eval(input()))
if k <= 9:
print(k)
else:
queue = deque()
for i in range(1, 10):
queue.append(i)
flag = 1
cnt_lunlun = 9
while flag:
first_element = queue.popleft()
... | from collections import deque
def main():
k = int(eval(input()))
if k <= 9:
print(k)
else:
queue = deque()
for i in range(1, 10):
queue.append(i)
flag = 1
cnt_lunlun = 9
while flag:
first_element = queue.popleft()
... | p02720 |
# -*- coding: utf-8 -*-
# D - Lunlun Number
# 標準入力の取得
K = int(eval(input()))
# 求解
def get_lunlun_number_list(ln_list:list) -> list:
lunlun_number_list = []
for ln in ln_list:
one_place_value = ln % 10
lunlun_number_list.append(int(str(ln) + str(one_place_value)))
if one_place... | # -*- coding: utf-8 -*-
# D - Lunlun Number
# モジュールのインポート
from collections import deque
# 標準入力の取得
K = int(eval(input()))
# 求解処理
# 空のQueueを一つ用意し、1, 2, ・・・, 9を順にEnqueue
que = deque(list(range(1, 10)))
lunlun_number = 0
for k in range(K):
# Queueに対して、Dequeueを行う
x = que.popleft()
# x mod 10 ≠ 0... | p02720 |
import heapq
k = int(eval(input()))
num_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
mae = 0
if k <= 9:
print(k)
else:
k -= 9
q = []
heapq.heapify(q)
for i in range(1, 10):
heapq.heappush(q, i)
temp = 0
while temp < 9:
temp += 1
num = heapq.heappop(q)
... | from collections import deque
k = int(eval(input()))
cnt = 9
q = deque([])
for i in range(1,10):
q.append(i)
ans = 0
if k < 10:
print(k)
else:
while cnt != k:
n = q.popleft()
if n%10 == 0:
tmp = n*10
q.append(n*10)
cnt += 1
... | p02720 |
# ABC161D
def f(k):
if 1 <= k <= 9:
print(k)
else:
nxt = [[0,1], [0,1,2], [1,2,3], [2,3,4], [3,4,5], [4,5,6], [5,6,7], [6,7,8], [7,8,9], [8,9]]
cum_npi = [0, 9, 35, 110, 327, 956, 2782, 8089, 23527, 68468, 199368]
for length, begin in enumerate(cum_npi):
if k ... | # ABC161D
def f(k):
if 1 <= k <= 9:
print(k)
else:
nxt = [[0,1], [0,1,2], [1,2,3], [2,3,4], [3,4,5], [4,5,6], [5,6,7], [6,7,8], [7,8,9], [8,9]]
cum_npi = [0, 9, 35, 110, 327, 956, 2782, 8089, 23527, 68468, 199368]
for length, begin in enumerate(cum_npi):
if ... | p02720 |
from collections import deque
a=int(eval(input()))
q=deque([1,2,3,4,5,6,7,8,9])
def dfs(k):
while k<=a:
s=q.popleft()
if s%10-1>=0:
q.append(s*10+s%10-1)
k=k+1
if k==a:
print((q.pop()))
q.append(s*10+s%10)
k=k+1
if k==a:
print((q.pop()))
if s%10... | from collections import deque
q=deque([1,2,3,4,5,6,7,8,9])
n=int(eval(input()))
def check(k):
while k<=n:
a=q.popleft()
if a%10-1>=0:
q.append(a*10+a%10-1)
k=k+1
if k==n:
return a*10+a%10-1
k=k+1
q.append(a*10+a%10)
if k==n:
return a*10+a%10
if a... | p02720 |
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
from itertools import product
def bisection(l,r,f,left=True,discrete=True):
eps=1 if(discrete) else 10**-8
if((not left)^f(r)): return r if(left) else r+1
elif(left^f(l))... | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
from itertools import product
def bisection(l,r,f,left=True,discrete=True):
eps=1 if(discrete) else 10**-8
if((not left)^f(r)): return r if(left) else r+1
elif(left^f(l))... | p02720 |
from collections import deque
K = int(eval(input()))
Q = deque([i for i in range(1,10)])
for _ in range(K-1):
q = Q.popleft()
if q%10 != 0:
Q.append(10*q+(q%10)-1)
Q.append(10*q+(q%10))
if q%10 != 9:
Q.append(10*q+(q%10)+1)
print((Q.popleft())) | from collections import deque
K = int(eval(input()))
Q = deque([i for i in range(1,10)])
for _ in range(K-1):
q = Q.popleft()
if q%10 != 0:
Q.append(q*10+q%10-1)
Q.append(q*10+q%10)
if q%10 != 9:
Q.append(q*10+q%10+1)
print((Q.popleft())) | p02720 |
from collections import deque
K = int(eval(input()))
Q = deque([i for i in range(1,10)])
for _ in range(K-1):
q = Q.popleft()
if q%10 != 0:
Q.append(q*10+q%10-1)
Q.append(q*10+q%10)
if q%10 != 9:
Q.append(q*10+q%10+1)
print((Q.popleft())) | from collections import deque
K = int(eval(input()))
q = deque([1,2,3,4,5,6,7,8,9])
for i in range(K):
num = q.popleft()
if num%10 != 0:
q.append(num*10+num%10-1)
q.append(num*10+num%10)
if num%10 != 9:
q.append(num*10+num%10+1)
print(num) | p02720 |
c = 0
K = int(eval(input()))
for i in range(1,10):
c += 1
if c == K:
print(i)
for i in range(1,10):
for j in range(i-1,min(i+2,10)):
c += 1
if c == K:
print((10*i+j))
for i in range(1,10):
for j in range(i-1,min(i+2,10)):
for k in range(max(j-... | import sys
from _collections import deque
K = int(eval(input()))
c = 9
A = [1,2,3,4,5,6,7,8,9]
q = deque(A)
if K <= 9:
print(K)
else:
while(True):
a = q.popleft()
if a % 10 == 0:
c += 1
if c == K:
print((a*10))
sys.exit()... | p02720 |
# import numpy as np
# import math
# import copy
from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
def main():
K = int(eval(input()))
queue = deque()
for i in range(1,10):
queue.append(i)
for i in range(K):
x = queue... | # import numpy as np
# import math
# import copy
from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
def main():
K = int(eval(input()))
pre = [i for i in range(1,10)]
now = []
if K <= 10:
print(K)
sys.exit()
count... | p02720 |
import sys
def is_lunlun(x):
x_str = str(x)
for i in range(len(x_str)-1):
if abs(int(x_str[i]) - int(x_str[i+1])) > 1:
return False
return True
def main():
k = int(eval(input()))
lunlun_map = {
0: [0, 1],
1: [0, 1, 2],
2: [1, 2, 3],
... | # Assumed solution
from collections import deque
def main():
k = int(eval(input()))
queue = deque()
for i in range(1, 10):
queue.append(i)
l = 0
for _ in range(k):
l = queue.popleft()
r = l % 10
if r != 0:
queue.append(l * 10 + r - 1)... | p02720 |
K=int(eval(input()))
u12 = [i for i in range(1,10)]
ans = 0
for i in range(K):
if ans <=11:
ans += 1
continue
flg = True
l = len(str(ans))
for j in range(l-1,-1,-1):
if 0<j<l-1:
x,y,z = list(map(int,str(ans)[j-1:j+2]))
if y!=9 and abs(x-(y+1))<... | from collections import deque
K=int(eval(input()))
ans =deque([i for i in range(1,10)])
for i in range(K):
x = ans.popleft()
mod_x=x%10
if mod_x != 0:
ans.append(x*10+mod_x-1)
ans.append(x*10+mod_x)
if x%10!=9:
ans.append(x*10+mod_x+1)
print(x) | p02720 |
k=int(eval(input()))
if k<=9:
print(k)
exit(0)
ans=[1,2,3,4,5,6,7,8,9]
i=0
while len(ans)<k:
v=str(ans[i])
n=len(v)
#最後の桁
v_last=int(v[-1])
if v_last==0:
ans.append(int(v+'0'))
ans.append(int(v+'1'))
elif v_last==9:
ans.append(int(v+'8'))
... | k=int(eval(input()))
if k<=9:
print(k)
exit(0)
ans=[1,2,3,4,5,6,7,8,9]
i=0
while len(ans)<k:
v=ans[i]
mod=v%10
if mod==0:
ans.append(10*v+mod)
ans.append(10*v+mod+1)
elif mod==9:
ans.append(10*v+mod-1)
ans.append(10*v+mod)
else:
... | p02720 |
from collections import deque
K = int(eval(input()))
d = deque([1,2,3,4,5,6,7,8,9])
ansq = deque([1,2,3,4,5,6,7,8,9])
while len(ansq)<=K:
num = d.popleft()
if str(num)[-1] == "0":
d.append(num*10)
d.append(num*10+1)
ansq.append(num*10)
ansq.append(num*10+1)
... | from collections import deque
K = int(eval(input()))
d = deque([1,2,3,4,5,6,7,8,9])
ansq = deque([1,2,3,4,5,6,7,8,9])
while len(ansq)<=K:
num = d.popleft()
if str(num)[-1] == "0":
da = num*10
db = num*10+1
d.append(da)
d.append(db)
ansq.append(da)
... | p02720 |
k = int(eval(input()))
a = []
def dfs(x):
a.append(x)
if x > 3234566667:
return
for i in range(10):
if abs(x % 10 - i) <= 1:
dfs(x * 10 + i)
for i in range(1, 10):
dfs(i)
a = sorted(a)
print((a[k - 1]))
| import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
k = int(eval(input()))
res = []
def dfs(x):
res.append(x)
if len(str(x)) == 10:
return
for i in range(10):
if abs(x % 10 - i) <= 1:
... | p02720 |
k = int(eval(input()))
# キュー
from collections import deque
d = deque()
for i in range(1,10):
d.append(i)
for i in range(k):
tmp = d.popleft()
right = tmp%10
if(right!=0):
d.append(tmp*10+right-1)
d.append(tmp*10+right)
if(right!=9):
d.append(tmp*10+right+1)
... | k = int(eval(input()))
def calc_dp(n):
if(n==0):
return 0
s = str(n)
slen = len(s)
dp = [[0] * 12 for _ in range(slen)]
dp_o = [[0] * 12 for _ in range(slen)]
#initial
for i in range(1,int(s[0])):
dp[0][i+1] = 1
dp_o[0][int(s[0])+1] = 1
#update
... | p02720 |
ln_l = [1,2,3,4,5,6,7,8,9]
def dps(curr_num):
end_num = curr_num[-1]
for i in [-1,0,1]:
added_num = int(end_num) + i
if added_num == -1 or added_num == 10:
continue
curr_num_plus = curr_num + str(added_num)
ln_l.append(int(curr_num_plus))
if len(cur... | def dfs(lls, curr_num, lim):
if curr_num > lim: return
lls.append(curr_num)
last_num = int(str(curr_num)[-1])
if last_num > 0:
dfs(lls, curr_num*10+last_num-1, lim)
if last_num < 9:
dfs(lls, curr_num*10+last_num+1, lim)
dfs(lls, curr_num*10+last_num, lim)
def main():... | p02720 |
def runrun(K,S):
if K <= len(S):
S.sort()
##print(S)
print((S[K-1]))
return
else:
for i in range(len(S)):
tmp = S[i]%10
if tmp == 9:
S.append(S[i]*10+8)
S.append(S[i]*10+9)
elif tmp == 0:
... | def lunlun(K,S):
if len(S) >= K:
S.sort()
print((S[K-1]))
return
for a in range(len(S)):
i = S[a]
rem = i%10
n = 10*i + rem
if rem == 9:
S.append(n)
S.append(n-1)
elif rem == 0:
S.append(n)
... | p02720 |
from collections import deque
K = int(eval(input()))
cnt = 0
q = deque()
for i in range(1, 10):
q.append(i)
while cnt < K:
num = q.popleft()
cnt += 1
if num%10 > 0:
q.append(10*num+(num%10)-1)
q.append(10*num+(num%10))
if num%10 < 9:
q.append(10*num+(num%10)+1)
... | K = int(eval(input()))
def f(n, k, a):
if k == n:
return 1
res = 0
res += f(n, k+1, a)
if a > 0:
res += f(n, k+1, a-1)
if a < 9:
res += f(n, k+1, a+1)
return res
cnt = 0
for n in range(1, 12):
c2 = 0
for a in range(1, 10):
c2 += f(n, 1... | p02720 |
import sys
from collections import deque
input = sys.stdin.readline
n=int(eval(input()))
L=deque(list(range(1,10)))
if n<=9:
ans = L[n-1]
else:
cnt = 9
for i in range(1,n):
c=L.popleft()
if c%10!=0:
L.append(c*10+(c%10)-1)
cnt+=1
... | import sys
from collections import deque
input = sys.stdin.readline
n=int(eval(input()))
L=deque([i for i in range(1,10)])
if n<=9:
ans = L[n-1]
else:
cnt = 9
for i in range(1,n):
c=L.popleft()
if c%10!=0:
L.append(c*10+(c%10)-1)
cnt+=1
... | p02720 |
import heapq
K = int(eval(input()))
Q = [1,2,3,4,5,6,7,8,9]
heapq.heapify(Q)
for i in range(K-1):
x = heapq.heappop(Q)
if x % 10 != 0:
heapq.heappush(Q,10*x+x%10-1)
heapq.heappush(Q,10*x+x%10)
if x % 10 != 9:
heapq.heappush(Q,10*x+x%10+1)
print((heapq.heappop(Q))) | from collections import deque
K = int(eval(input()))
Q = deque([1,2,3,4,5,6,7,8,9])
for i in range(K-1):
x = Q.popleft()
if x % 10 != 0:
Q.append(10*x+x%10-1)
Q.append(10*x+x%10)
if x % 10 != 9:
Q.append(10*x+x%10+1)
print((Q.popleft())) | p02720 |
from collections import deque
K = int(eval(input()))
d = deque()
for i in range(1, 10):
d.append(i)
cnt = 0
while d:
tmp = d.popleft()
cnt += 1
if cnt == K:
print(tmp)
break
r = tmp % 10
if r != 0:
d.append(tmp * 10 + r - 1)
d.append(tmp * 10 + r)
... | K = int(eval(input()))
import copy
present = [1,2,3,4,5,6,7,8,9]
while K >= len(present):
K -= len(present)
next = []
for i in range(len(present)):
tmp = present[i]
r = tmp % 10
if r != 0:
next.append(tmp * 10 + r -1)
next.append(tmp * 10 + r)
... | p02720 |
K = int(eval(input()))
import copy
present = [1,2,3,4,5,6,7,8,9]
while K >= len(present):
K -= len(present)
next = []
for i in range(len(present)):
tmp = present[i]
r = tmp % 10
if r != 0:
next.append(tmp * 10 + r -1)
next.append(tmp * 10 + r)
... | K = int(eval(input()))
old = []
old = [i for i in range(1, 10)]
while K > len(old):
new = []
K -= len(old)
for i in range(len(old)):
tmp = old[i]
l = tmp % 10
if l != 0:
new.append(tmp*10+l-1)
new.append(tmp*10+l)
if l != 9:
ne... | p02720 |
def function(n):
string = str(n)
for i in range(len(string) - 1):
if int(string[i]) - int(string[i + 1]) > 1:
return i + 1
elif int(string[i + 1]) - int(string[i]) > 1:
return i
return -1
k = int(eval(input()))
ans = []
n = 1
while len(ans) < k:
m = function(n)
if m == -1:
... | def function(n):
string = str(n)
for i in range(len(string) - 1):
error = int(string[i]) - int(string[i + 1])
if error > 1:
return i + 1, error
elif error < -1:
return i, abs(error)
return -1, 0
k = int(eval(input()))
ans = []
n = 1
while len(ans) < k:
m, error = function... | p02720 |
def d():
k = int(eval(input()))
val = 0
hits = 0
hit_tails = {}
while hits < k:
val += 1
if len(str(val)) == 1:
hits += 1
hit_tails[val] = int(str(val)[-1])
# print('====', hits, val)
pass
else:
lst = ... | from collections import deque
def lunlun():
k = int(eval(input()))
q = deque(list(range(1, 10)))
while k > 0:
k -= 1
n = q.popleft()
# print('====== popleft:', n)
if n % 10 != 0:
n0 = int(str(n) + str(n % 10 - 1))
q.append(n0)
... | p02720 |
from collections import deque
def main():
k = int(eval(input()))
# 前後をチェックする再帰関数( 要素として深さも必要そう / DPのメモ化とか使えそう )
#
# 生データ
# 1桁
# [1, 2, 3, 4, 5, 6, 7, 8, 9]
# 2桁
# [10, 11, 12, 21, 22, 23,..., 98, 99]
#
# 1
# 10 11 12
#
# 2
# .. .. .. 21 22 23
#
# Point.
... | from collections import deque
def main():
k = int(eval(input()))
# 前後をチェックする再帰関数( 要素として深さも必要そう / DPのメモ化とか使えそう )
#
# 生データ
# 1桁
# [1, 2, 3, 4, 5, 6, 7, 8, 9]
# 2桁
# [10, 11, 12, 21, 22, 23,..., 98, 99]
#
# 1
# 10 11 12
#
# 2
# .. .. .. 21 22 23
#
# Point.
... | p02720 |
# D - Lunlun Number
K = int(eval(input()))
stack = [1, 2, 3, 4, 5, 6, 7, 8, 9]
i = 0
while len(stack) < K:
first = int(str(stack[i])[-1:])
if first == 0:
stack.append(int(str(stack[i]) + str(first)))
stack.append(int(str(stack[i]) + str(first + 1)))
elif first == 9:
stack... | # D - Lunlun Number
K = int(eval(input()))
N = [1, 2, 3, 4, 5, 6, 7, 8, 9]
i = 0
while len(N) < K:
n = int(str(N[i]) + str(N[i])[-1:])
if str(n)[-1:] == '0':
N += [n, n + 1]
elif str(n)[-1:] == '9':
N += [n - 1, n]
else:
N += [n - 1, n, n + 1]
i += 1
prin... | p02720 |
import sys
input = sys.stdin.readline
from collections import deque
INF = float('inf')
if __name__ == '__main__':
K = int(eval(input()))
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
if K < 10:
print(K)
exit()
counter = 0
while True:
counter += 1
x = q... | import sys
input = sys.stdin.readline
from collections import deque
INF = float('inf')
if __name__ == '__main__':
K = int(eval(input()))
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
if K < 10:
print(K)
exit()
counter = 0
while True:
counter += 1
x = q... | p02720 |
import sys
input = sys.stdin.readline
from collections import deque
INF = float('inf')
if __name__ == '__main__':
K = int(eval(input()))
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
if K < 10:
print(K)
exit()
counter = 0
while True:
counter += 1
x = q... | import sys
input = sys.stdin.readline
from collections import deque
INF = float('inf')
if __name__ == '__main__':
K = int(eval(input()))
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
if K < 10:
print(K)
exit()
counter = 0
while True:
counter += 1
x = q... | p02720 |
k = int(eval(input()))
n = 0
def ff(s, i):
for j in range(i+1, len(s)):
#print(s[j-1])
if s[j-1] > 0:
s[j] = s[j-1] - 1
else:
s[j] = 0
return s
def next(s):
ls = len(s)
for i in range(ls-1, 0, -1):
if s[i-1] >= s[i] and s[i] != 9:
... | k = int(eval(input()))
r = [[i] for i in range(1,10)]
from collections import deque
que = deque(r)
if k < 10:
print(k)
exit()
while len(r) <= k:
ri = que.popleft()
for j in range(max(0, ri[-1]-1), min(9, ri[-1]+1)+1):
rj = ri.copy()
rj.append(j)
r.append(rj)
... | p02720 |
MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)
K = int(eval(input()))
lunlun = []
def dfs(i,before):
if i == 11:
return
lunlun.append(before)
back = before%10
for j in range(-1,2):
t = back + j
if 0 <= t < 10:
dfs(i + 1,... | import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
Lunlun = []
K = int(eval(input()))
def dfs(i,before):
if i == 10:
return
Lunlun.append(before)
x = before%10
for d in (-1,0,1):
y = x + d
if y < 0 or y >= 10:
continue
... | p02720 |
def main():
from functools import lru_cache
import sys
sys.setrecursionlimit(10 ** 7)
@lru_cache(maxsize=None)
def make_number(digit, p=0):
if digit == 0:
memo.append(p)
if len(memo) == k + 1:
print(p)
exit()
... | from collections import deque
K = int(eval(input()))
dq = deque()
for x in range(1, 10):
dq.append(x)
idx = 1
while idx < K:
x = dq.popleft()
idx += 1
r = x % 10
if r > 0:
nx = (x * 10) + (r - 1)
dq.append(nx)
nx = (x * 10) + (r)
dq.append(nx)
... | p02720 |
from collections import deque
K = int(eval(input()))
dq = deque()
for x in range(1, 10):
dq.append(x)
idx = 1
while idx < K:
x = dq.popleft()
idx += 1
r = x % 10
if r > 0:
nx = (x * 10) + (r - 1)
dq.append(nx)
nx = (x * 10) + (r)
dq.append(nx)
... | def main():
from collections import deque
K = int(eval(input()))
dq = deque()
for x in range(1, 10):
dq.append(x)
idx = 0
while dq:
x = dq.popleft()
idx += 1
if idx == K:
print(x)
return
r = x % 10
if r... | p02720 |
def is_valid(num):
if 1 <= num < 10:
return True
ns = list(map(int, str(num)))
n = len(ns)
for i in range(n - 1):
if abs(ns[i] - ns[i + 1]) > 1:
return False
return True
lunluns = []
for i in range(1, 100000):
if is_valid(i):
lunluns.append(i)
... | # 20/05/10 cost:20min
def is_valid(num):
if 1 <= num < 10:
return True
ns = list(map(int, str(num)))
n = len(ns)
for i in range(n - 1):
if abs(ns[i] - ns[i + 1]) > 1:
return False
return True
lunluns = []
for i in range(1, 10):
if is_valid(i):
... | p02720 |
def make_tree(G,keta,count):
if keta==1:
num =[]
for i in range(1,10):
count+=1
if count ==k:
print(i)
exit()
else:
num.append(i)
G.append(num)
make_tree(G,2,count)
else:
... | def is_count_k(count,n):
count +=1
if count == k :
print(n)
exit()
return count
def make_tree(G,keta,count):
num_list = G[keta-2]
new_list =[]
for num in num_list:
r = num%10
if r != 0 :
count = is_count_k(count,num*10 + (r-1))
... | p02720 |
import sys
sys.setrecursionlimit(3000)
k = int(eval(input()))
ans = []
def solve(x, l):
if int(x) > 3234566667:
return l
l.append(int(x))
if x[-1] == '0':
solve(x + '0', l)
solve(x + '1', l)
elif x[-1] == '9':
solve(x + '9', l)
solve(x + '8', l)... | from collections import deque
k = int(eval(input()))
#初めに、1~9まではキューに入れておく
q = deque([i for i in range(1, 10)])
ans = 0
while True:
v = q.popleft()
ans += 1
if ans == k:
print(v)
break
#末尾の1桁を求める
last_digit = v % 10
#求めた末尾の1桁との差が1になる数字を最後の1桁にする
#つまり、末尾の... | p02720 |
def add():
for i in ans[cnt-1]:
i=str(i)
last=i[-1]
last=int(last)
for j in range(last-1,last+2):
if j==10 or j==-1:
continue
tmp=i
tmp+=str(j)
ans[cnt].append(int(tmp))
n=int(eval(input()))
ans=[[]for i in... | def dfs(x):
ans.append(x)
if len(str(x))==10:
return
last=x%10
for i in [last-1,last,last+1]:
if 0<=i<=9:
dfs(10*x+i)
k=int(eval(input()))
ans=[]
for i in range(1,10):
dfs(i)
ans=sorted(ans)
print((ans[k-1]))
| p02720 |
k = int(eval(input()))
a = list(map(str, list(range(1, 10))))
ans = a + []
illist = []
for i in range(10):
if i == 0:
illist.append(["0","1"])
elif i == 9:
illist.append(["8","9"])
else:
illist.append([str(i-1),str(i),str(i+1)])
while len(ans) < k:
b = []
for i i... | k = int(eval(input()))
from collections import deque
q = deque()
a = list(map(str, list(range(1, 10))))
ans = a + []
illist = []
for i in range(10):
if i == 0:
illist.append(["0","1"])
elif i == 9:
illist.append(["8","9"])
else:
illist.append([str(i-1),str(i),str(i+1)])
... | p02720 |
K=int(eval(input()))
N=0 #現在のルンルン数の数
lun=list(range(1,10))
while 1:
N+=1
x=lun[N-1]
if x%10 != 0:
lun.append(10*x+x%10-1)
lun.append(10*x+x%10)
if x%10 != 9:
lun.append(10*x+x%10+1)
if N==K:
break
print((lun[N-1]))
| K=int(eval(input()))
# K=15
lun=list(range(1,10))
i=0
while 1:
ichi=lun[i]%10
if ichi!=0:
lun.append(lun[i]*10+ichi-1)
lun.append(lun[i]*10+ichi)
if ichi!=9:
lun.append(lun[i]*10+ichi+1)
i+=1
if i==K:
break
print((lun[i-1]))
| p02720 |
# -*- coding: utf-8 -*-
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in rang... | # -*- coding: utf-8 -*-
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in rang... | p02720 |
#n桁のるんるん数のrisutoを求める
import sys
sys.setrecursionlimit(10**9)
def runrun(n):
if n == 1:
return [['1','2','3','4','5','6','7','8','9']]
else:
li = runrun(n-1)
li2 = []
for i in range(len(li[n-2])):
p = int(li[n-2][i][-1])
if p == 0:
... | #n桁のるんるん数のrisutoを求める
import sys
sys.setrecursionlimit(10**9)
from functools import lru_cache
@lru_cache(maxsize=None)
def runrun(n):
if n == 1:
return [['1','2','3','4','5','6','7','8','9']]
else:
li = runrun(n-1)
li2 = []
for i in range(len(li[n-2])):
... | p02720 |
import collections
k = int(eval(input()))
Q = collections.deque([int(i) for i in range(1, 10)])
for _ in range(k):
x = Q.popleft()
if x%10:
Q.append(10*x + x%10 - 1)
Q.append(10*x + x%10)
if x%10 != 9:
Q.append(10*x + x%10 + 1)
print(x)
| import collections
k = int(eval(input()))
Q = collections.deque([int(i) for i in range(1, 10)])
chk = False
for i in range(k):
x = Q.popleft()
if i + len(Q) > k:
chk = True
if chk:
continue
else:
if x%10:
Q.append(10*x + x%10 - 1)
Q.append(10*x ... | p02720 |
import collections
k = int(eval(input()))
Q = collections.deque([int(i) for i in range(1, 10)])
chk = False
for i in range(k):
x = Q.popleft()
if i + len(Q) > k:
chk = True
if chk:
continue
else:
if x%10:
Q.append(10*x + x%10 - 1)
Q.append(10*x ... | import collections
def main():
k = int(eval(input()))
Q = collections.deque([int(i) for i in range(1, 10)])
chk = False
for i in range(k):
x = Q.popleft()
if i + len(Q) > k:
chk = True
if chk:
continue
else:
if x%10:
... | p02720 |
import sys
from collections import deque
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
K = ir()
A = deque([x for x in range(1, 10)])
count = 0
while True:
cur = A.popleft()
count += 1
if count == K:
answer = cur
b... | # coding: utf-8
import sys
sys.setrecursionlimit(10 ** 7)
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
K = ir()
num = -1
def dfs(A, i, bl):
global num
if i == 11:
num += 1
if num == K:
ans = ''.join(map... | p02720 |
K = int(eval(input()))
k = K - 1
numbers = {
0: 1
}
while k > 0:
k -= 1
for i in range(len(numbers)):
n = numbers[i]
if n == 9:
continue
if abs(numbers.get(i - 1, n) - (n + 1)) <= 1 and abs(numbers.get(i + 1, n) - (n + 1)) <= 1:
numbers[i] ... | from collections import deque
K = int(eval(input()))
queue = deque(list(range(1, 10)))
for _ in range(K):
x = queue.popleft()
if x % 10 != 0:
queue.append(10 * x + x % 10 - 1)
queue.append(10 * x + x % 10)
if x % 10 != 9:
queue.append(10 * x + x % 10 + 1)
print(x)
| p02720 |
import sys
from collections import deque
def solve():
input = sys.stdin.readline
K = int(eval(input()))
low, high = 0, 3234566668
while high - low > 1:
mid = (low + high) // 2
midS = str(mid)
lenS = len(midS)
q = deque()
fo... | import sys
from collections import deque
def solve():
input = sys.stdin.readline
K = int(eval(input()))
q = deque()
for i in range(9): q.append((i + 1, i + 1))
lunlun = 1
while lunlun < K:
nowNum, lastNum = q.popleft()
if lastNum > 0: q.append((nowNum * 10 + lastNum -... | p02720 |
K = int(eval(input()))
a = set([1,2,3,4,5,6,7,8,9])
prev = set([1,2,3,4,5,6,7,8,9])
while len(a) < K:
temp = set()
for now in prev:
c = now%10
if c == 0:
temp.add(now*10)
temp.add(now*10+1)
elif c == 9:
temp.add(now*10+9)
temp... | K = int(eval(input()))
S = set([1,2,3,4,5,6,7,8,9])
prev = set([1,2,3,4,5,6,7,8,9])
while len(S) < K:
temp = set([])
for e in prev:
if e%10 == 0:
temp.add(e*10)
temp.add(e*10+1)
elif e%10 == 9:
temp.add(e*10+8)
temp.add(e*10+9)
... | p02720 |
k = int(eval(input()))
def dfs(d, val, A):
A.append(val)
if d == 10:
return
for i in range(-1, 2):
add = (val % 10) + i
if add >= 0 and add <= 9:
dfs(d + 1, val * 10 + add, A)
A = []
for v in range(1, 10): # 呼び出し
dfs(1, v, A)
A.sort()
print((A[k - 1])) |
def calc_next(arr):
res = []
for val in arr:
for j in range(-1, 2):
add = (val % 10) + j
if add >= 0 and add <= 9:
res.append(val * 10 + add)
return res
k = int(eval(input()))
cur = []
A = []
for v in range(1, 10):
cur.append(v)
A.append(v)
for d in range(1, 10):
cur = calc_next... | p02720 |
from collections import deque
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
K = int(readline())
queue = deque([])
for i in range(1,10):
queue.append(i)
for i in range(K):
x = queue.popleft()
r = ... | # 桁dp + 二分探索
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def lunlun_num(N):
N = str(N)
L = len(N)
dp = [[0]*10 for j in range(L)]
for j in range(1,int(N[0])):
dp[0][j] = 1
flag = True
for i in range(L-1):
d = i... | p02720 |
def solve():
K = int(eval(input()))
cnt = 0
n_digit = 1
numbers = []
while cnt < K:
numbers = []
dfs("", numbers, n_digit)
cnt += len(numbers)
n_digit += 1
print((numbers[-(cnt - K + 1)]))
def dfs(now, numbers, n_digit):
if len(now) == ... | from collections import deque
def solve():
K = int(eval(input()))
q = deque(list(range(1,10)))
cnt = 0
tmp = 0
while cnt < K:
tmp = q.popleft()
cnt += 1
ones_place = tmp % 10
if ones_place != 0:
q.append(tmp*10+ones_place-1)
q.appen... | p02720 |
def solve():
K = int(eval(input()))
all = []
for i in range(1,10):
dfs(1,i,all)
all.sort()
print((all[K-1]))
def dfs(d, val, all):
all.append(val)
if d == 10:
return
for j in [-1,0,1]:
add = val % 10 + j
if 0 <= add <= 9:
... | def solve():
K = int(eval(input()))
lunluns = []
for i in range(1,10):
dfs(1,i,lunluns)
lunluns.sort()
print((lunluns[K-1]))
def dfs(d,now,lunluns):
lunluns.append(now)
if d == 10:
return
for i in [-1,0,1]:
add = now % 10 + i
... | p02720 |
import sys
sys.setrecursionlimit(20000000)
k = int(eval(input()))
def dfs(l, lim):
if lim == 10:
return l
new_l = []
for num in l:
last = num % 10
base = num * 10
if 1 <= last <= 8:
for i in [last-1, last, last+1]:
if base + i <= 3234... | from collections import deque
k = int(eval(input()))
que = deque([i for i in range(1, 10)])
i = 0
while True:
i += 1
num = que.popleft()
if i == k:
print(num)
exit()
if num % 10 > 0:
que.append(num * 10 + ((num % 10) - 1))
que.append(num * 10 + (num % 10))
... | p02720 |
# -*- coding: utf-8 -*-
from collections import deque
k = int(eval(input()))
dq = deque(list(range(1, 10)))
rep = 0
while rep < k:
now = dq.popleft()
rep+=1
for i in (-1, 0, 1):
if 0<=now%10+i<10:
dq.append(now*10+now%10+i)
print(now)
| def main():
k = int(eval(input()))
a = [i for i in range(1,10)]
x = 0
while(1):
if k <= len(a):
print((a[k-1]))
return
for i in range(-1,2):
d = a[x]%10 +i
if 0 <= d and d < 10:
a.append(a[x]*10 + d)
x+=1... | p02720 |
n = int(eval(input()))
l = [_ for _ in range(1,10)]
for i in range(10**5):
if str(l[i])[-1] == '0':
l.append(l[i]*10 + int(str(l[i])[-1]))
l.append(l[i]*10 + int(str(l[i])[-1]) + 1)
elif str(l[i])[-1] == '9':
l.append(l[i]*10 + int(str(l[i])[-1]) - 1)
l.append(l[i]*10... | n = int(eval(input()))
l = [_ for _ in range(1,10)]
cnt = 9
for i in range(10**5):
if cnt >= n:
break
if str(l[i])[-1] == '0':
l.append(l[i]*10 + int(str(l[i])[-1]))
l.append(l[i]*10 + int(str(l[i])[-1]) + 1)
cnt += 2
elif str(l[i])[-1] == '9':
l.append... | p02720 |
from collections import deque
q = deque([1,2,3,4,5,6,7,8,9])
cnt = 0
l = []
used = set()
while cnt<100000:
p = q.popleft()
if p in used:continue
used.add(p)
l.append(p)
cnt += 1
for i in range(max((p%10)-1,0), min((p%10)+1, 9)+1):
q.append(10*p+i)
N = int(eval(input())... | from collections import deque
def solve():
N = int(eval(input()))
q = deque([1,2,3,4,5,6,7,8,9])
cnt = 0
l = []
used = set()
while cnt<N:
p = q.popleft()
if p in used:continue
used.add(p)
l.append(p)
cnt += 1
for i in range(max((... | p02720 |
from collections import deque
def solve():
N = int(eval(input()))
q = deque([1,2,3,4,5,6,7,8,9])
cnt = 0
l = []
used = set()
while cnt<N:
p = q.popleft()
if p in used:continue
used.add(p)
l.append(p)
cnt += 1
for i in range(max((... | from collections import deque
def solve():
N = int(eval(input()))
q = deque([1,2,3,4,5,6,7,8,9])
cnt = 0
l = []
while cnt<N:
p = q.popleft()
l.append(p)
cnt += 1
for i in range(max((p%10)-1,0), min((p%10)+1, 9)+1):
q.append(10*p+i)
... | p02720 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
k = int(readline())
q = [(i + 1) for i in range(9)]
if k < 10:
print(k)
exit()
cnt = 9
while q:
x = q.pop(0)
y = int(str(x)[-1])
if y != ... | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from collections import deque
k = int(readline())
q = deque(list(map(str, list(range(1, 10)))))
for i in range(k - 1):
x = q.popleft()
y = int(x[-1])
... | p02720 |
import sys
from collections import deque
sys.setrecursionlimit(10**7)
k = int(eval(input()))
ans = []
def bfs(que):
finished = set()
while que and len(ans) <= 10**6:
x = que.popleft()
ans.append(int(x))
if x not in finished:
finished.add(x)
p = int(x[-... | import sys
from collections import deque
sys.setrecursionlimit(10**7)
k = int(eval(input()))
ans = []
def bfs(que):
finished = set()
while que and len(ans) <= 10**5:
x = que.popleft()
ans.append(int(x))
if x not in finished:
finished.add(x)
p = int(x[-... | p02720 |
K = int(eval(input()))
L = [i for i in range(1, 10)]
cnt = 9
i = 0
while K > cnt:
x = L[i]
r = x % 10
if r != 0:
L.append(10*x + r - 1)
cnt += 1
L.append(10*x + r)
cnt += 1
if r != 9:
L.append(10*x + r + 1)
cnt += 1
i += 1
print((L[K-1])) | K = int(eval(input()))
C = [[0]*10 for _ in range(10)]
C[0] = [1]*10
D = {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]}
for i in range(1, 10):
for j in range(10):
if j == 0:
C[i][j] = C[i-1][j] + C[i-1][j+1]
... | p02720 |
N=int(eval(input()))
list = []
def standard(n, cur):
if n == 0:
##print(''.join(cur))
add = ''.join(cur)
if str(add).isnumeric() and add != "0":
list.append(int(add))
else:
newC = chr(ord(cur[-1]) + 1)
standard(n - 1, cur + [newC])
newC2 = chr(ord(cur[-1]) - 1)
st... | N=int(eval(input()))
list = []
def standard(n, cur):
if n == 0:
add = ''.join(cur)
if str(add).isnumeric():
list.append(int(add))
else:
newC = chr(ord(cur[-1]) - 1)
standard(n - 1, cur + [newC])
newC2 = chr(ord(cur[-1]))
standard(n - 1, cur + [newC2])
newC3 = chr(or... | p02720 |
K = int(eval(input()))
def cal():
count = 9
d = [[1,2,3,4,5,6,7,8,9]]
for i in range(10**9):
d_ = []
for j in range(len(d[i])):
a = str(d[i][j])
if a[-1]=="0":
for k in [0, 1]:
d_.append(int(a)*10+k)
... | from collections import deque
k = int(eval(input()))
if k <= 9: print(k)
que = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
count = 9
while count <= k:
X = que.popleft()
if X%10==0: check=[0, 1]
elif X%10==9: check=[8, 9]
else: check = [X%10-1, X%10, X%10+1]
for i in check:
que.append(X*10+... | p02720 |
from collections import deque
def main():
K = int(eval(input()))
num_list = list(range(0, 10))
def bfs():
q = deque(list(map(str, num_list)))
while len(num_list) < 2 * 10**6:
now_str = q.popleft()
now = int(now_str[0])
for j in [now-1,... | from collections import deque
def main():
K = int(eval(input()))
# bfs
count = 0
q = deque(list(range(1, 10)))
while count < K-1:
now = q.popleft()
count += 1
d1 = now % 10
base = 10 * now
for suffix in [d1 - 1, d1, d1 + 1]:
i... | p02720 |
from collections import deque
def main():
K = int(eval(input()))
# bfs
count = 0
q = deque(list(range(1, 10)))
while count < K-1:
now = q.popleft()
count += 1
d1 = now % 10
base = 10 * now
for suffix in [d1 - 1, d1, d1 + 1]:
i... | from collections import deque
def main():
K = int(eval(input()))
# bfs
q = deque(list(range(1, 10)))
for _ in range(K-1):
now = q.popleft()
d1 = now % 10
base = 10 * now
for suffix in [d1 - 1, d1, d1 + 1]:
if suffix not in [-1, 10]... | p02720 |
import queue
K = int(eval(input()))
q = queue.Queue()
for i in range(1, 10):
q.put(i)
for _ in range(K):
x = q.get()
d = x%10
t = x*10
if d != 0:
q.put(t-1+d)
q.put(t+d)
if d != 9:
q.put(t+1+d)
print(x) | # coding: utf-8
# d 現在の桁
# val 現在の値
# all 格納
def rec(d, val, all):
# 格納
all.append(val)
# 10桁なら終了
if d == 10:
return
# 再帰
for i in range(-1, 2):
add = val%10 + i
if 0 <= add <= 9:
rec(d+1, val*10+add, all)
# main
K = int(eval(input()))
all =... | p02720 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.