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. 在Linux下安装ArcGIS10.2

    最近由于工作需要,沉迷可视化无法自拔,一直在研究基于GIS的地图可视化,自己在本机windows搭建了一个ArcGIS服务器,用Tableau和R调用WMS服务成功,不愧是GIS元老级应用,效果超赞. ...

  2. python-成员修饰符

    python的面相对象中,拥有3个成员,字段.方法.属性 class Foo: def __init__(self,name): #公有字段name在类中与类外均能调用 self.name = nam ...

  3. [转]unity之LOD

    LOD技术有点类似于Mipmap技术,不同的是,LOD是对模型建立了一个模型金字塔,根据摄像机距离对象的远近,选择使用不同精度的模型. 它的好处是可以在适当的时候大量减少需要绘制的顶点数目. 它的缺点 ...

  4. 通过设计表快速了解sql语句中字段的含义

    打开Navicat-------> 选择数据库 ------->右键设计表------>查看下方注释

  5. android自定义控件属性

    有两种方法为自定义的控件设置属性 . 来自为知笔记(Wiz)

  6. Java中Object.equals和String.equals的区别详解

    前言 Java中的堆和常量池的区别是什么呢?Object.equals与String.equals的区别呢?下面让我们通过一个小示例让你明白它- 1.基础知识 Java的存储空间:寄存器.栈.堆.静态 ...

  7. 201621123034 《Java程序设计》第11周学习总结

    作业11-多线程 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 1. 源代码阅读:多线程程序BounceThread ...

  8. Rational Rose 使用技巧

    1.浏览区 2.菜单项 其中Format选项中: 决定各项是否显示,也可以通过右击-option选择 3.常用快捷键: F1:任何时候都可以按F1获得相关帮助,把鼠标放在某条菜单上按F1可以获得这条菜 ...

  9. linux安装软件的几种方法

    一.rpm包安装方式步骤: 1.找到相应的软件包,比如soft.version.rpm,下载到本机某个目录: 2.打开一个终端,su -成root用户: 3.cd soft.version.rpm所在 ...

  10. windows系统设备管理器显示全部硬件

    下面的小命令能让隐藏的未卸载掉的硬件设备彻底现身:开始-运行-CMD C:\> C:\>start devmgmt.msc 之后再在Windows 的设备管理器中,单击菜单“显示”-“显示 ...