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 = ababcabab and ababc are substrings of s, while acz and an empty string are not. Also, we say that substrings are different when they are different as strings.

Let X=x1x2xn and Y=y1y2ym be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or xj>yj where j is the smallest integer such that xjyj.

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: ababba 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

    一看这种题第一反应:裸上SAM啊!
但是一看数据范围:艹这是连SAM都不用的傻逼题了。
因为字典序第K小肯定不会超过K位,所以直接暴力+去重就可以做了QWQ
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=5005;
string ch[maxn*6];
char s[maxn];
int n,k,cnt;
int main(){
scanf("%s%d",s,&k),n=strlen(s);
for(int i=0,T;i<n;i++){
ch[++cnt]=s[i];
T=min(k,n-i);
for(int j=1;j<T;j++,cnt++) ch[cnt+1]=ch[cnt]+s[i+j];
} sort(ch+1,ch+cnt+1);
unique(ch+1,ch+cnt+1);
cout<<ch[k]<<endl;
return 0;
}

  

 

AtCoder - 4130 K-th Substring的更多相关文章

  1. AtCoder Beginner Contest 043 D - アンバランス / Unbalanced

    题目链接:http://abc043.contest.atcoder.jp/tasks/arc059_b Time limit : 2sec / Memory limit : 256MB Score ...

  2. LeetCode第[5]题(Java):Longest Palindromic Substring 标签:String、动态规划

    题目中文:求最长回文子串 题目难度:Medium 题目内容: Given a string s, find the longest palindromic substring in s. You ma ...

  3. sql 取汉字首字母

    )) ) --用于加密 --WITH ENCRYPTION as begin declare @intLen int ) ) set @intLen = len(@str) set @strRet = ...

  4. sql 函数 汉字转拼音

    GO /****** Object: UserDefinedFunction [dbo].[fn_GetPy] Script Date: 2017/1/4 10:53:49 ******/ SET A ...

  5. Pjax调用

    $.pjax({container:'#content_center',url:href,data:data}); $(document).on('pjax:send', function() {// ...

  6. 都别说工资低了,我们来一起写简单的dom选择器吧!

    前言 我师父(http://www.cnblogs.com/aaronjs/)说应当阅读框架(jquery),所以老夫就准备开始看了 然后公司的师兄原来写了个dom选择器,感觉不错啊!!!原来自己从来 ...

  7. Leetcode: Encode String with Shortest Length && G面经

    Given a non-empty string, encode the string such that its encoded length is the shortest. The encodi ...

  8. JAVA时间格式转换大全

    import java.text.*; import java.util.Calendar; public class VeDate { /** * 获取现在时间 * * @return 返回时间类型 ...

  9. Spark中常用工具类Utils的简明介绍

    <深入理解Spark:核心思想与源码分析>一书前言的内容请看链接<深入理解SPARK:核心思想与源码分析>一书正式出版上市 <深入理解Spark:核心思想与源码分析> ...

随机推荐

  1. Python运算符及逻辑运算

    基本运算符 运算符用于执行程序代码运算,会针对一个以上操作数项目来进行运算.例如:2+3,其操作数是2和3,而运算符则是“+”.在计算器语言中运算符大致可以分为5种类型:算术运算符.连接运算符.关系运 ...

  2. [译]11-spring bean定义的继承

    spring中bean的定义包含很多信息,如,构造器参数.property指定的依赖项.初始化方法.工厂类和工厂方法等. 如果spring容器的中每个bean都重复声明这些属性,是非常烦人也是十分低效 ...

  3. serial console

    适用于: agent_ipmitool_socat pxe_ipmitool_socat 修改driver方式:更换ironic node的driver类型 yum install -y socat ...

  4. Where can I find the IPA logs

    Retrieving the IPA logs will differ depending on which base image was used. Operating system that do ...

  5. CentOS下Apache虚拟主机配置

    通过phpinfo可以看到Apache安装的目录 修改配置文件,首先将配置文件备份 编辑httpd.conf,并找到虚拟路径配置的部分 vi httpd.conf 在vi下先按esc在键入 :/vho ...

  6. c++知识点总结-模板特化

    类模板的全特化与偏特化 类模板 template<typename T1, typename T2> class Test { public: Test(T1 i,T2 j):a(i),b ...

  7. Struts2+DAO层实现实例03——添加监听器跟踪用户行为

    实例说明 根据上两次的成品进行二次加工. 加入Listener,监听用户的登陆注销情况. 所用知识说明 采用SessionBindingListener对Session进行监听. 同时,Action中 ...

  8. GDI+实现双缓冲绘图方法一

    private void Form5_MouseMove(object sender, MouseEventArgs e) { int intOX = rectDrawArea.X; int intO ...

  9. 后端model传入前端JSP页面中的值判断后再取值

    所遇到的问题后端model传入前端JSP页面中的值通过foreach循环内要满足条件才能取值给Div中,我们知道jsp页面中可以直接用EL表达式取值,格式就是${"model中传来的数据&q ...

  10. (转)彻底隐藏Nginx版本号的安全性与方法

    Nginx默认是显示版本号的,如: [root@bkjz ~]# curl -I www.nginx.orgHTTP/1.1 200 OKServer: nginx/0.8.44Date: Tue, ...