Problem:


Score : 300 points

Problem Statement

You are given a string s.
Among the different substrings of s, print the K-th lexicographically smallest one.

A substring of s is a string obtained by taking out a non-empty contiguous part in s.
For example, if s = ababc, a, bab and ababc are substrings of s, while ac, z and an empty string are not.
Also, we say that substrings are different when they are different as strings.

Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Constraints

1 ≤ |s| ≤ 5000

s consists of lowercase English letters.

1 ≤ K ≤ 5

s has at least K different substrings.

Partial Score

200 points will be awarded as a partial score for passing the test set satisfying |s| ≤ 50.

Input

Input is given from Standard Input in the following format:

s
K

Output

Print the K-th lexicographically smallest substring of K.

Sample Input 1

aba
4

Sample Output 1

b

s has five substrings: a, b, ab, ba and aba.
Among them, we should print the fourth smallest one, b.
Note that we do not count a twice.

Sample Input 2

atcoderandatcodeer
5

Sample Output 2

andat

Sample Input 3

z
1

Sample Output 3

z



Sample input:
aba
4


Sample output:
b

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
ans_lis = []


def check(s, kosu):
    lis_kosu = []
    for i in range(len(s) - kosu + 1):
        lis_kosu.append(s[i:i + kosu])
    return list(set(lis_kosu))


for i in range(1, len(s) + 1):
    ans_lis += check(s, i)


print(sorted(ans_lis)[K - 1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
 
S = []
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        S.append(s[i:j])
        
S = list(set(S))
for i in range(K):
    ans = min(S)
    S.remove(ans)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())

S = []
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        S.append(s[i:j])

S = sorted(list(set(S)))

print(S[K-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())

N = len(s)

d = dict()
for i in range(N):
    for j in range(i, N):
        sub = s[i:j+1]
        if d.get(sub) == None:
            d[sub] = 1

d2 = sorted(d.items())
print(d2[K-1][0])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())

N = len(s)

d = dict()
for i in range(N):
    for j in range(i, N):
        sub = s[i:j+1]
        if d.get(sub) == None:
            d[sub] = 1

d2 = sorted(d.items())
print(d2[K-1][0])

Submission status: Time Limit Exceeded

Solution code:
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

######################################################

S=input()
N=len(S)
K=intput()
L=[list()]*26
ans=[]
for i in range(N):
    L[ston(S[i])].append(i)
for l in L:
    for i in l:
        for j in range(i+1,N+1):
            s=S[i:j]
            if bisect_left(ans,s)==bisect_right(ans,s):
                insort_left(ans,s)
    if len(ans)>=K:
        print(ans[K-1])
        exit()

Submission status: Time Limit Exceeded

Solution code:
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

######################################################

S=input()
N=len(S)
K=intput()
L=[]
for i in range(N):
    for j in range(i+1,N+1):
        s=S[i:j]
        if bisect_left(L,s)!=bisect_right(L,s):
            continue
        insort_left(L,s)
        if len(L)>K:
            L=L[:K]
print(L[-1])

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=len(S)
K=int(input())

from collections import*
ans=set([])
for i in range(1,N+1):
    now=S[:i]
    ans.add(now)
    now=list(now)
    now=deque(now)
    for s in S[i:]:
        now.append(s)
        now.popleft()
        a=''.join(now)
        ans.add(a)
ans=sorted(list(ans))
print(ans[K-1])

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=len(S)
K=int(input())

ans=set([])
for i in range(1,N+1):
    j=0
    while j+i<=N:
        ans.add(S[j:j+i])
        j+=1
ans=sorted(list(ans))
print(ans[K-1])

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def run():
    S = input()
    K = int(input())
    dic = set()
    pos = defaultdict(lambda : [])
    for i, s in enumerate(S):
        pos[s].append(i)
    base = 'abcdefghijklmnopqrstuvwxyz'

    for l in base:
        for position in pos[l]:
            for k in range(position+1, len(S)+1):
                dic.add(S[position:k])
        if len(dic) >= K:break

    dic = sorted(list(dic))
    print(dic[K-1])



if __name__ == "__main__":
    run()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def run():
    S = input()
    K = int(input())
    dic = set()
    for k in range(1, len(S)+1):
        for p in range(len(S)-k+1):
            sub = S[p:p+k]
            dic.add(sub)
    dic = sorted(list(dic))
    print(dic[K-1])


if __name__ == "__main__":
    run()

Submission status: Time Limit Exceeded

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

dic = {}
for i in range(1,len(s)+1):
    for j in range(len(s)+1-i):
        dic.setdefault(s[j:j+i],0)
        dic[s[j:j+i]] += 1
sort_dic = sorted(dic)
print(sort_dic[k-1])

Submission status: Time Limit Exceeded

Solution code:
'''
Created on 2020/08/26

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  s=pin()[:-1]
  K=int(pin())
  d=[]
  for i in range(1,len(s)+1):
    ans=[]
    for j in range(len(s)-i+1):
      ans.append(s[j:j+i])
    d=sorted(d+sorted(list(set(ans))))
  print(d[K-1])
  return 
main()

Submission status: Time Limit Exceeded

Solution code:
'''
Created on 2020/08/26

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  s=pin()[:-1]
  K=int(pin())
  d=[]
  for i in range(1,len(s)+1):
    for j in range(len(s)-i+1):
      t=s[j:j+i]
      if t not in d:
        d.append(t)
  l=sorted(d)
  print(l[K-1])
  return 
main()

Submission status: Time Limit Exceeded

Solution code:
'''
Created on 2020/08/26

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  s=pin()[:-1]
  K=int(pin())
  d=[]
  for i in range(1,len(s)+1):
    for j in range(len(s)-i+1):
      t=s[j:j+i]
      d.append(t)
    d.sort()
  l=sorted(list(set(d)))
  print(l[K-1])
  return 
main()

Submission status: Time Limit Exceeded

Solution code:
'''
Created on 2020/08/26

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  s=pin()[:-1]
  K=int(pin())
  d=[]
  for i in range(1,len(s)+1):
    for j in range(len(s)-i+1):
      t=s[j:j+i]
      d.append(t)
  l=sorted(list(set(d)))
  print(l[K-1])
  return 
main()

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort

S=input()
K=int(input())

T=[]
N=len(S)
for  i in range(N):
    V=""
    for j in range(i,N):
        V+=S[j]
        if V not in T:
            insort(T,S[i:j+1])
            T=T[:K]
print(T[-1])

Submission status: Time Limit Exceeded

Solution code:
S=input()
K=int(input())

T=set()
N=len(S)
for  i in range(N):
    for j in range(i,N):
        if S[i:j+1] not in T:
            T.add(S[i:j+1])
T=sorted(list(T))
print(T[K-1])

Submission status: Time Limit Exceeded

Solution code:

s = input()
k = int(input())
dd = {}
if len(s) == 1:
    print(s)
    exit()
for i in range(len(s)):
    dd[s[i]] = 1
for i in range(len(s)-1):
    for j in range(i+1, len(s)):
        dd[s[i:j+1]] = 1
li = []
for key in dd:
    li.append(key)
li.sort()
print(li[k-1])

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
s = input()
k = int(input())
dd = {}
if len(s) == 1:
    print(s)
    exit()
for i in range(len(s)):
    dd[s[i]] = 1
for i in range(len(s)-1):
    for j in range(i+1, len(s)):
        dd[s[i:j+1]] = 1
li = []
for key in dd:
    li.append(key)
li.sort()
print(li[k-1])

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
s = input()
k = int(input())
dd = defaultdict(lambda:0)
if len(s) == 1:
    print(s)
    exit()
for i in range(len(s)):
    dd[s[i]] = 1
for i in range(len(s)-1):
    for j in range(i+1, len(s)):
        dd[s[i:j+1]] = 1
li = []
for key in dd:
    li.append(key)
li.sort()
print(li[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
n = len(s)
char_list = []
for i in range(n):
    if s[i] not in char_list:
        char_list.append(s[i])
char_list.sort()
# print(char_list)

cnt = 0
str_list = []
for i in range(len(char_list)):
    for j in range(n):
        if s[j] == char_list[i]:
            for k in range(j, n + 1):
                str_list.append(s[j:k + 1])
    if len(list(set(str_list))) < K:
        continue
    else:
        str_list = list(set(str_list))
        str_list.sort()
        print(str_list[K - 1])
        # print(str_list)
        exit()

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
s=input()
s_list=list(s)
length=len(s)
K=int(input())
o=[]
x=deque(sorted(set(s)))



while len(o) < K:
    letter=x.popleft()
    X=[i for i , x in enumerate(s_list) if x==letter]
    for i in X:
        for j in range(i+1,length+1):
            if not s[i:j] in o:
                o.append(s[i:j])




o.sort()
print(o[K-1])

Submission status: Time Limit Exceeded

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

begin, end = 0, 1

# 辞書順先頭となる1文字目を探索

top = S[0]
idxs = {0}

for idx, s in enumerate(S):
    if ord(s) < ord(top):
        idxs = {idx}
        top = s
    elif ord(s) == ord(top):
        idxs.add(idx)

orders = {top}
while len(orders) < k:
    flag = False
    for idx in idxs:
        ptr = 2
        while idx + ptr < len(S) + 1 and ptr < 7:
            orders.add(S[idx: idx + ptr])
            flag = True
            ptr += 1
    if not flag:
        break


if len(orders) < k:
    second = chr(123)
    idxs = set()
    for idx, s in enumerate(S):
        if s != top:
            if ord(s) < ord(second):
                idxs = {idx}
                second = s
            elif ord(s) == ord(second):
                idxs.add(idx)

    orders.add(second)
    ptr = 2
    while len(orders) < 5:
        flag = False
        for idx in idxs:
            ptr = 2
            while idx + ptr < len(S) + 1 and ptr < 7:
                orders.add(S[idx: idx + ptr])
                flag = True
                ptr += 1
        if not flag:
            break

print(sorted(list(orders))[k - 1])

Submission status: Time Limit Exceeded

Solution code:
s = list(input().strip())
K = int(input())
C = {}
for i in range(len(s)):
    if s[i] not in C:
        C[s[i]] = []
    C[s[i]].append(i)
D = set()
for a in C:
    for i in C[a]:
        x=s[i]
        D.add(x)
        for j in range(i+1,len(s)):
            x += s[j]
            D.add(x)
D = sorted(list(D))
print(D[K-1])

Submission status: Time Limit Exceeded

Solution code:
s = input().strip()
K = int(input())
C = {}
for i in range(len(s)):
    if s[i] not in C:
        C[s[i]] = []
    C[s[i]].append(i)
D = {}
for a in C:
    for i in C[a]:
        x = s[i]
        if x not in D:
            D[x] = 0
        D[x] += 1
        for j in range(i+1,len(s)):
            x += s[j]
            if x not in D:
                D[x] = 0
            D[x] += 1
D = sorted(list(D.keys()))
print(D[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
s = input()
k = int(input())
ans = [[] for _ in range(k)]
x = list(set(s))
cnt = 0
for i in range(1,k+1):
    for v in itertools.product(x, repeat=i):
        y = "".join(v)
        if y in s and y not in ans[i-1]: 
            ans[i-1].append(y)
ans = list(itertools.chain.from_iterable(ans))
ans.sort()
print(ans[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = input().strip()
K = int(input())
C = {}
for i in range(len(s)):
    if s[i] not in C:
        C[s[i]] = []
    C[s[i]].append(i)
D = {}
for a in C:
    for i in C[a]:
        for j in range(i+1,len(s)+1):
            if s[i:j] not in D:
                D[s[i:j]] = 0
            D[s[i:j]] += 1
D = sorted(list(D.keys()))
print(D[K-1])

Submission status: Time Limit Exceeded

Solution code:
s = input().strip()
K = int(input())
C = {}
for i in range(len(s)):
    if s[i] not in C:
        C[s[i]] = []
    C[s[i]].append(i)
if len(C)==1:
    a = s[0]
    print(a*K)
else:
    A = []
    for a in C:
        for i in C[a]:
            for j in range(i+1,len(s)+1):
                A.append(s[i:j])
    A = sorted(list(set(A)))
    print(A[K-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
n=len(s)
ans=set()
for i in range(1,n+1):
  for j in range(n-i+1):ans.add(s[j:j+i])
ans=sorted(list(set(ans)))
print(ans[k-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
n=len(s)
ans=[]
for i in range(1,n+1):
  for j in range(n-i+1):ans.append(s[j:j+i])
ans=sorted(list(set(ans)))
print(ans[k-1])

Submission status: Time Limit Exceeded

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

n = len(s)
S = set()
for i in range(n):
    for j in range(i+1, n+1):
        t = s[i:j]
        S.add(t)
S = list(S)
S.sort()
print(S[k-1])

Submission status: Time Limit Exceeded

Solution code:
#coding: utf-8

S = input()
K = int(input())

subs = set()

for i in range(len(S)):
    for j in range(i+1,len(S)+1):
        subs.add(S[i:j])

print(sorted(list(subs))[K-1])

Submission status: Time Limit Exceeded

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = input()
k = INT()
a = set()
for i in range(len(s)):
    t = s[i]
    b = sorted(list(a))
    if len(b) > k and t > b[-1]:
        continue
    else:
        a.add(t)
    if i < len(s) - 1:
        for j in range(i+1, len(s)):
            t += s[j]
            a.add(t)
b = sorted(list(a))
print(b[k-1])

Submission status: Time Limit Exceeded

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = input()
k = INT()
a = set()
for i in range(len(s)):
    t = s[i]
    a.add(t)
    if i < len(s) - 1:
        for j in range(i+1, len(s)):
            t += s[j]
            a.add(t)
b = sorted(list(a))
print(b[k-1])

Submission status: Time Limit Exceeded

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = input()
k = INT()
a = set()
for i in range(len(s)):
    for j in range(i, len(s)):
        a.add(s[i:j+1])
b = sorted(list(a))
print(b[k-1])

Submission status: Time Limit Exceeded

Solution code:
# kが極端に少ないので、下位K個を管理してよさそうな気がする
# -> なんかダメ
# じゃ決め打ちして全探索することにしてみる どうせ長さは最大でKなので
# 時間的に間に合うか微妙な気がする
# -> はい

s = list(input())
k = int(input())
d = {}
for i in range(len(s)):
    for j in range(i, len(s)):
        t = "".join(s[i:j + 1])
        if t not in d:
            d[t] = True
dk = sorted(d.keys())
print(dk[k - 1])

Submission status: Time Limit Exceeded

Solution code:
# kが極端に少ないので、下位K個を管理してよさそうな気がする
# -> なんかダメ
# じゃ決め打ちして全探索することにしてみる どうせ長さは最大でKなので
# 時間的に間に合うか微妙な気がする
# -> はい

s = list(input())
k = int(input())
d = {}
ans = []
for i in range(len(s)):
    for j in range(i, len(s)):
        t = "".join(s[i:j + 1])
        if t not in d:
            d[t] = True
            ans.append(t)
print(sorted(ans)[k - 1])

Submission status: Time Limit Exceeded

Solution code:
# kが極端に少ないので、下位K個を管理してよさそうな気がする
# -> なんかダメ
# じゃ決め打ちして全探索することにしてみる どうせ長さは最大でKなので
# 時間的に間に合うか微妙な気がする
from string import ascii_lowercase
s = input()
k = int(input())
cur = 0


def f(v):
    global cur
    if len(v) <= k:
        if v in s:
            cur += 1
        if cur == k:
            print(v)
            exit()
        else:
            for c in ascii_lowercase:
                f(v + c)


for c in ascii_lowercase:
    f(c)

Submission status: Time Limit Exceeded

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

abc='abcdefghijklmnopqrstuvwxyz'

def dfs(keta,ns):
  global cnt
  if ns in s:
    cnt+=1
  if cnt==k:
    print(ns)
    exit()
  if keta==k:
    return

  for i in abc:
    dfs(keta+1,ns+i)

cnt=0
for i in abc:
  dfs(1,i)

Submission status: Time Limit Exceeded

Solution code:
S = input().strip()
N = len(S)
K = int(input())
A = [ord(S[i]) for i in range(N)]
cnt = 0
a0 = 96
while True:
    amin = 1000
    for i in range(N):
        if a0<A[i]<=amin:
            amin = A[i]
    Ind = []
    for i in range(N):
        if A[i]==amin:
            Ind.append(i)
    a0 = amin
    B = []
    for i in Ind:
        for j in range(i,N):
            x = S[i:j+1]
            if x not in B:
                B.append(x)
    B = sorted(B)
    k = K-cnt
    if len(B)>=k:
        ans = B[k-1]
        break
    else:
        cnt += len(B)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
n=len(s)
a=[]
for i in range(n):
  for j in range(1,k+1):
    a=set(a)|set([s[i:i+j]])
a=sorted(a)
print(a[k-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
n=len(s)
a=[]
for i in range(n):
  for j in range(i+1,n+1):
    a=set(a)|set([s[i:j]])
a=sorted(a)
print(a[k-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
K=int(input())
d=['zzzzz']
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        for k in range(len(d)):
            if s[i:j] not in d and s[i:j]<d[k]:
                d.insert(k,s[i:j])
                if len(d)>5:
                    d.pop()
                break
print(d[K-1])

Submission status: Time Limit Exceeded

Solution code:
def main():
    import heapq,bisect
    s = input()
    K = int(input())

    n = len(s)

    L = []
    for i in range(n):
        for j in range(i+1,n+1):
            l = bisect.bisect_left(L,s[i:j])
            if l < len(L):
                if L[l] == s[i:j]:
                    continue

            if l < K:
                L.insert(l,s[i:j])
    # print(L)
    print(L[K-1])

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    K = int(input())

    n = len(s)

    L = set()
    for i in range(n):
        for j in range(i+1,n+1):
            L.add(s[i:j])
    L = list(L)
    L.sort()
    print(L[K-1])

main()

Submission status: Time Limit Exceeded

Solution code:
a = input()
n = int(input())
t = 1
ar = []
while True:
    for i in range(len(a) - t + 1):
        if a[i:i+t] not in ar:
            ar.append(a[i:i+t])
    t += 1
    if t > len(a):
        break
ar.sort()
print(ar[n-1])

Submission status: Time Limit Exceeded

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    s = input()
    k = int(input())
    ss = set()
    alp = "abcdefghijklmnopqrstuvwxyz"
    for ai in alp:
        for i,si in enumerate(s):
            if si != ai:
                continue
            nw = ""
            for sj in s[i::]:
                nw += sj
                ss.add(nw)
        if len(ss) >= k:
            break
    print(sorted(ss)[k-1])



    return

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    s = input()
    k = int(input())
    ss = set()
    for i in range(len(s)):
        nw = ""
        for sj in s[i::]:
            nw += sj
            ss.add(nw)

    print(sorted(ss)[k-1])



    return

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
if __name__ == "__main__":
    s = input()
    subsrings = []
    K = int(input())
    for i in range(len(s)):
        subsrings.append(s[i:])
    subsrings.sort()

    first = set()

    for s in subsrings:
        for i in range(1, len(s) + 1):
            if s[:i] not in first:
                first.add(s[:i])
                if len(first) == K:
                    print(s[:i])
                    break

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/arc097/tasks/arc097_a

s = input()
K = int(input())
k = K
done = set()
for i in range(26):
    w = chr(i + ord('a'))
    for j in range(len(s)):
        if s[j] == w:
            for m in range(j, len(s)):
                t = s[j:m + 1]
                if t not in done:
                    k -= 1
                    done.add(t)
    if k < 1:
        done = list(done)
        done.sort()
        print(done[K - 1])
        import sys;sys.exit()

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/arc097/tasks/arc097_a

s = input()
k = int(input())

done = set()
for i in range(26):
    w = chr(i + ord('a'))
    for j in range(len(s)):
        if s[j] == w:
            for m in range(j, len(s)):
                t = s[j:m + 1]
                if t not in done:
                    k -= 1
                    done.add(t)
    if k < 1:
        done = list(done)
        done.sort()
        print(done[k - 1])
        import sys;sys.exit()

Submission status: Time Limit Exceeded

Solution code:
import sys
from heapq import heapify, heappop

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    S = input()
    k = int(input())
    n = len(S)

    SS = set()
    for i in range(n):
        ss = [S[i]]
        SS.add("".join(ss))
        for j in range(i + 1, n):
            ss.append(S[j])
            SS.add("".join(ss))

    SS = list(SS)
    heapify(SS)
    for _ in range(k):
        res = heappop(SS)
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
from heapq import heapify, heappop

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    S = input()
    k = int(input())
    n = len(S)

    SS = set()
    for i in range(n):
        ss = S[i]
        SS.add(ss)
        for j in range(i + 1, n):
            ss += S[j]
            SS.add(ss)

    SS = list(SS)
    heapify(SS)
    for _ in range(k):
        res = heappop(SS)
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    S = input()
    k = int(input())
    n = len(S)

    SS = set()
    for i in range(n):
        ss = S[i]
        SS.add(ss)
        for j in range(i + 1, n):
            ss += S[j]
            SS.add(ss)
    SS = sorted(list(SS))
    print(SS[k - 1])


if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
K = int(input())
ans = set()
for c in "abcdefghijklmnopqrstuvwxyz":
    for i in range(N):
        if S[i] == c:
            for j in range(i + 1, N + 1):
                ans.add(S[i:j])
    if len(ans) >= K:
        break
print(sorted(list(ans))[K - 1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
#ss = sorted(set(s))

sList = []
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        sList.append(s[i:j])
sSet = sorted(set(sList))

print(sSet[k-1])

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
k=int(input())
n=len(s)
subset=set([])
for i in range(n):
    tmp=s[i]
    subset.add(tmp)
    for j in range(i+1, n):
        tmp+=s[j]
        subset.add(tmp)
subset=sorted(list(subset))
print(subset[k-1])

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
k=int(input())
n=len(s)
subset=set([])
for i in range(n):
    tmp=[s[i]]
    subset.add(tmp[0])
    for j in range(i+1, n):
        tmp.append(s[j])
        subset.add(''.join(tmp))
subset=sorted(list(subset))
print(subset[k-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
K=int(input())
D=[]
for i in range(len(s)+1):
  for j in range(len(s)-i):
    D.append(s[i:i+j+1])
D = sorted(list(set(D)))
#print(D)
print(D[K-1])