总共有
个字符串,每两个字符串比较的复杂度是
,所以全部拉出来排序的复杂度是
,不能通过
但注意到题目的限制条件
,我们考虑到一个串的前缀的字典序一定比它小,所以最后答案字符串的长度不会超过5
所以我们把所有长度不超过5的字符串拉出来排序就好,注意去重,复杂度
#include <bits/stdc++.h>
using namespace std;
set<string> ss;
string a[200048],s;
int tot=0,k;
int main ()
{
cin>>s>>k;
int i,j,n=int(s.size());
for (i=0;i<=n-1;i++)
for (j=1;j<=5;j++)
{
if (i+j-1>=n) continue;
ss.insert(s.substr(i,j));
}
for (i=1;i<=k-1;i++) ss.erase(ss.begin());
cout<<(*(ss.begin()))<<endl;
return 0;
}