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. 常用模块(time)

    import time # data = time.time() # 获取时间戳# data = time.localtime() # 获取操作系统时间,也称本地时间,可传入时间戳# data = t ...

  2. 设置hostname

    由于 http://1.2.3.4 不是一个有效的 apt 源,安装肯定会失败,我们可以在 /var/log/cloud-init.log 看到失败的信息. cloud-init 默认会将 insta ...

  3. Python namedtuple(命名元组)使用实例

    Python namedtuple(命名元组)使用实例 #!/usr/bin/python3 import collections MyTupleClass = collections.namedtu ...

  4. hadoop-搭建(转)--亲测好用 (一)

    1)JDK软件 下载地址:http://www.oracle.com/technetwork/java/javase/index.html 2)Hadoop软件 下载地址:http://hadoop. ...

  5. windows mobile 开发:让GPS一直在待机模式下也能运行

    最近,遇到一个需求,就是每 30 秒更新一次 GPS 位置,在测试过程中,发现在系统待机后,更新 GPS 位置就不能正常运行了,搜索后,发现如下的解决方案,实际应用了之后,有效,赞!!! http:/ ...

  6. 使用Cookie保存用户和密码然后自动登录

    login.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  7. Using Let’s Encrypt for free SSL Certs with Netscaler

    Using Let’s Encrypt for free SSL Certs with Netscaler If you haven’t heard, Let’s Encrypt (https://l ...

  8. C++11 tuple元组

    C++11 tuple 元组 tuple容器(元组), 是表示元组容器, 是不包含任何结构的,快速而低质(粗制滥造, quick and dirty)的, 可以用于函数返回多个返回值; tuple容器 ...

  9. 花花的礼物 (huahua)

    花花的礼物 (huahua) 花花是个爱动脑子的孩子,在她的生日的时候,她的爸爸给她准备了个礼物.但是,她的爸爸并不想让她轻易得到礼物,他把礼物放在了一个箱子里面,只有输入正确的密码才能打开箱子,而她 ...

  10. macOS Sierra下如何打开任何来源(10.12系统)

    转载声明:本站文章无特别说明皆为原创,转载请注明:史蒂芬周的博客, 一定有很多朋友和小子一样,迫不及待的升级到了macOS Sierra,随之而来的是第三方应用都无法打开了,提示无法打开或者扔进废纸篓 ...