Official
C - Concat (X-th) Editorial by en_translator
The problem can be solved by actually constructing the \(N^K\) strings and sorting them.
It is easy to enumerate the \(N^K\) strings using DFS (Depth-First Search).
Writer’ solution (Python)
N,K,X=map(int,input().split())
S=[input() for _ in range(N)]
ans=[]
def dfs(crr, count):
# Now, `count` strings have been concatenating, resulting in the string `crr`
if count==K:
ans.append(crr)
return
for s in S:
dfs(crr+s, count+1)
dfs("", 0)
ans.sort()
print(ans[X-1])
posted:
last update: